rem
stringlengths
0
83.5k
add
stringlengths
0
223k
context
stringlengths
10
471k
meta
stringlengths
120
236
#ifndef SIMPLE_MAN2HTML
static void request_while( char*& c, int j, bool mdoc ){ // ### TODO: .break and .continue#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Entering .while" << endl;#endif c += j; char* newline = skip_till_newline( c ); const char oldchar = *newline; *newline = 0; // We store the full .while stuff into a QCString as if it would be a macro const QCString macro = c ;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "'Macro' of .while" << endl << macro << endl;#endif // Prepare for continuing after .while loop end *newline = oldchar; c = newline; // Process -while loop const bool oldwhileloop = s_whileloop; s_whileloop = true; int result = true; // It must be an int due to the call to scan_expression while ( result ) { // Unlike for a normal macro, we have the condition at start, so we do not need to prepend extra bytes char* liveloop = qstrdup( macro.data() );#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Scanning .while condition" << endl;#endif char* end_expression = scan_expression( liveloop, &result ); if ( result ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "New .while iteration" << endl;#endif // The condition is true, so call the .while's content char* help = end_expression + 1; while ( *help && ( *help == ' ' || *help == '\t' ) ) ++help; if ( ! *help ) { // We have a problem, so stop .while result = false; break; } if ( mdoc ) scan_troff_mandoc( help, false, 0 ); else scan_troff( help, false, 0 ); } delete[] liveloop; } // s_whileloop = oldwhileloop;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Ending .while" << endl;#endif}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static void request_while( char*& c, int j, bool mdoc ){ // ### TODO: .break and .continue#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Entering .while" << endl;#endif c += j; char* newline = skip_till_newline( c ); const char oldchar = *newline; *newline = 0; // We store the full .while stuff into a QCString as if it would be a macro const QCString macro = c ;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "'Macro' of .while" << endl << macro << endl;#endif // Prepare for continuing after .while loop end *newline = oldchar; c = newline; // Process -while loop const bool oldwhileloop = s_whileloop; s_whileloop = true; int result = true; // It must be an int due to the call to scan_expression while ( result ) { // Unlike for a normal macro, we have the condition at start, so we do not need to prepend extra bytes char* liveloop = qstrdup( macro.data() );#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Scanning .while condition" << endl;#endif char* end_expression = scan_expression( liveloop, &result ); if ( result ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "New .while iteration" << endl;#endif // The condition is true, so call the .while's content char* help = end_expression + 1; while ( *help && ( *help == ' ' || *help == '\t' ) ) ++help; if ( ! *help ) { // We have a problem, so stop .while result = false; break; } if ( mdoc ) scan_troff_mandoc( help, false, 0 ); else scan_troff( help, false, 0 ); } delete[] liveloop; } // s_whileloop = oldwhileloop;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Ending .while" << endl;#endif}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static void request_while( char*& c, int j, bool mdoc ){ // ### TODO: .break and .continue#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Entering .while" << endl;#endif c += j; char* newline = skip_till_newline( c ); const char oldchar = *newline; *newline = 0; // We store the full .while stuff into a QCString as if it would be a macro const QCString macro = c ;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "'Macro' of .while" << endl << macro << endl;#endif // Prepare for continuing after .while loop end *newline = oldchar; c = newline; // Process -while loop const bool oldwhileloop = s_whileloop; s_whileloop = true; int result = true; // It must be an int due to the call to scan_expression while ( result ) { // Unlike for a normal macro, we have the condition at start, so we do not need to prepend extra bytes char* liveloop = qstrdup( macro.data() );#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Scanning .while condition" << endl;#endif char* end_expression = scan_expression( liveloop, &result ); if ( result ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "New .while iteration" << endl;#endif // The condition is true, so call the .while's content char* help = end_expression + 1; while ( *help && ( *help == ' ' || *help == '\t' ) ) ++help; if ( ! *help ) { // We have a problem, so stop .while result = false; break; } if ( mdoc ) scan_troff_mandoc( help, false, 0 ); else scan_troff( help, false, 0 ); } delete[] liveloop; } // s_whileloop = oldwhileloop;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Ending .while" << endl;#endif}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static void request_while( char*& c, int j, bool mdoc ){ // ### TODO: .break and .continue#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Entering .while" << endl;#endif c += j; char* newline = skip_till_newline( c ); const char oldchar = *newline; *newline = 0; // We store the full .while stuff into a QCString as if it would be a macro const QCString macro = c ;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "'Macro' of .while" << endl << macro << endl;#endif // Prepare for continuing after .while loop end *newline = oldchar; c = newline; // Process -while loop const bool oldwhileloop = s_whileloop; s_whileloop = true; int result = true; // It must be an int due to the call to scan_expression while ( result ) { // Unlike for a normal macro, we have the condition at start, so we do not need to prepend extra bytes char* liveloop = qstrdup( macro.data() );#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Scanning .while condition" << endl;#endif char* end_expression = scan_expression( liveloop, &result ); if ( result ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "New .while iteration" << endl;#endif // The condition is true, so call the .while's content char* help = end_expression + 1; while ( *help && ( *help == ' ' || *help == '\t' ) ) ++help; if ( ! *help ) { // We have a problem, so stop .while result = false; break; } if ( mdoc ) scan_troff_mandoc( help, false, 0 ); else scan_troff( help, false, 0 ); } delete[] liveloop; } // s_whileloop = oldwhileloop;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Ending .while" << endl;#endif}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static void request_while( char*& c, int j, bool mdoc ){ // ### TODO: .break and .continue#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Entering .while" << endl;#endif c += j; char* newline = skip_till_newline( c ); const char oldchar = *newline; *newline = 0; // We store the full .while stuff into a QCString as if it would be a macro const QCString macro = c ;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "'Macro' of .while" << endl << macro << endl;#endif // Prepare for continuing after .while loop end *newline = oldchar; c = newline; // Process -while loop const bool oldwhileloop = s_whileloop; s_whileloop = true; int result = true; // It must be an int due to the call to scan_expression while ( result ) { // Unlike for a normal macro, we have the condition at start, so we do not need to prepend extra bytes char* liveloop = qstrdup( macro.data() );#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Scanning .while condition" << endl;#endif char* end_expression = scan_expression( liveloop, &result ); if ( result ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "New .while iteration" << endl;#endif // The condition is true, so call the .while's content char* help = end_expression + 1; while ( *help && ( *help == ' ' || *help == '\t' ) ) ++help; if ( ! *help ) { // We have a problem, so stop .while result = false; break; } if ( mdoc ) scan_troff_mandoc( help, false, 0 ); else scan_troff( help, false, 0 ); } delete[] liveloop; } // s_whileloop = oldwhileloop;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Ending .while" << endl;#endif}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static void request_while( char*& c, int j, bool mdoc ){ // ### TODO: .break and .continue#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Entering .while" << endl;#endif c += j; char* newline = skip_till_newline( c ); const char oldchar = *newline; *newline = 0; // We store the full .while stuff into a QCString as if it would be a macro const QCString macro = c ;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "'Macro' of .while" << endl << macro << endl;#endif // Prepare for continuing after .while loop end *newline = oldchar; c = newline; // Process -while loop const bool oldwhileloop = s_whileloop; s_whileloop = true; int result = true; // It must be an int due to the call to scan_expression while ( result ) { // Unlike for a normal macro, we have the condition at start, so we do not need to prepend extra bytes char* liveloop = qstrdup( macro.data() );#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Scanning .while condition" << endl;#endif char* end_expression = scan_expression( liveloop, &result ); if ( result ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "New .while iteration" << endl;#endif // The condition is true, so call the .while's content char* help = end_expression + 1; while ( *help && ( *help == ' ' || *help == '\t' ) ) ++help; if ( ! *help ) { // We have a problem, so stop .while result = false; break; } if ( mdoc ) scan_troff_mandoc( help, false, 0 ); else scan_troff( help, false, 0 ); } delete[] liveloop; } // s_whileloop = oldwhileloop;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Ending .while" << endl;#endif}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static QCString scan_identifier( char*& c ){ char* h = c; // help pointer // ### TODO Groff seems to eat nearly everything as identifier name (info:/groff/Identifiers) while ( *h && *h != '\a' && *h != '\n' && is_identifier_char( *h ) ) ++h; const char tempchar = *h; *h = 0; const QCString name = c; *h = tempchar; if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: identifier empty!" << endl;#endif } c = h; return name;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static QCString scan_identifier( char*& c ){ char* h = c; // help pointer // ### TODO Groff seems to eat nearly everything as identifier name (info:/groff/Identifiers) while ( *h && *h != '\a' && *h != '\n' && is_identifier_char( *h ) ) ++h; const char tempchar = *h; *h = 0; const QCString name = c; *h = tempchar; if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: identifier empty!" << endl;#endif } c = h; return name;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer ); #else
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif } #ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j); #else
}
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h); #else
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h); #else
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('R'));
out_html(set_font("R"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('R'));
out_html(set_font("R"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('R'));
out_html(set_font("R"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('R'));
out_html(set_font("R"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('B'));
out_html(set_font("B"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('R'));
out_html(set_font("R"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('B'));
out_html(set_font("B"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('R'));
out_html(set_font("R"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible"); #else
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('I'));
out_html(set_font("I"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('R'));
out_html(set_font("R"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('B'));
out_html(set_font("B"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('R'));
out_html(set_font("R"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('B'));
out_html(set_font("B"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('R'));
out_html(set_font("R"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('R'));
out_html(set_font("R"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('R'));
out_html(set_font("R"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('R'));
out_html(set_font("R"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('R'));
out_html(set_font("R"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('I'));
out_html(set_font("I"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('R'));
out_html(set_font("R"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('I'));
out_html(set_font("I"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('R'));
out_html(set_font("R"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('B'));
out_html(set_font("B"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('R'));
out_html(set_font("R"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('R'));
out_html(set_font("R"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('B'));
out_html(set_font("B"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('R'));
out_html(set_font("R"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('B'));
out_html(set_font("B"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('R'));
out_html(set_font("R"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('I'));
out_html(set_font("I"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
out_html(set_font('R'));
out_html(set_font("R"));
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#ifndef SIMPLE_MAN2HTML
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp
#endif
static char *scan_request(char *c){ // mdoc(7) stuff static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mdoc(7) page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) // man(7) stuff static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) int i=0; bool mode=false; char *h=0; const int max_wordlist=100; char *wordlist[max_wordlist]; int words; char *sl; while (*c==' ' || *c=='\t') c++; // Spaces or tabs allowed between control character and request if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Found .\\$" << endl;#endif c=skip_till_newline(c); // ### TODO } else c = scan_escape(c+1); } else { int j; if (c[1]=='\n') j=1; else j=2; // ### TODO: remove, as i is over-written later int nlen = 0; QCString macroName; while (c[nlen] && (c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) { macroName+=c[nlen]; nlen++; } j = nlen; while (c[j] && c[j]==' ' || c[j]=='\t') j++; /* search macro database of self-defined macros */ QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(macroName); if (it!=s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "CALLING MACRO: " << macroName << endl;#endif const QCString oldDollarZero = s_dollarZero; // Previous value of $0 s_dollarZero = macroName; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for ( i=words; i<max_wordlist; i++ ) wordlist[i]=NULL; if ( !(*it).m_output.isEmpty() ) { //kdDebug(7107) << "Macro content is: " << endl << (*it).m_output << endl; const unsigned int length = (*it).m_output.length(); char* work = new char [length+2]; work[0] = '\n'; // The macro must start after an end of line to allow a request on first line qstrncpy(work+1,(*it).m_output.data(),length+1); const QValueList<char*> oldArgumentList( s_argumentList ); s_argumentList.clear(); for ( i = 0 ; i < max_wordlist; i++ ) { if (!wordlist[i]) break; s_argumentList.push_back( wordlist[i] ); } const int onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc( work + 1, 0, NULL ); else scan_troff( work + 1, 0, NULL); delete[] work; newline_for_fun=onff; s_argumentList = oldArgumentList; } for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; s_dollarZero = oldDollarZero;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "ENDING MACRO: " << macroName << endl;#endif } else {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "REQUEST: " << macroName << endl;#endif switch (int request = get_request(c, nlen)) { case REQ_ab: // groff(7) "ABort" { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0';#ifdef SIMPLE_MAN2HTML fprintf( stderr, "%s\n", buffer );#else kdDebug(7107) << "ABORT: " << buffer << endl;#endif }#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s\n", c+j);#else // ### TODO find a way to display it to the user kdDebug(7107) << "Aborting: .ab " << (c+j) << endl;#endif return 0; break; } case REQ_An: // mdoc(7) "Author Name" { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: // groff(7) "end current DIversion" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .di" << endl;#endif c+=j; if (*c=='\n') { ++c; break; } const QCString name ( scan_identifier( c ) ); while (*c && *c!='\n') c++; c++; h=c; while (*c && qstrncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; char* result=0; scan_troff(h,0,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { (*it).m_length=0; (*it).m_output=result; } delete[] result; if (*c) *c='.'; c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .di" << endl;#endif break; } case REQ_ds: // groff(7) "Define String variable" mode=true; case REQ_as: // groff (7) "Append String variable" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .ds/.as" << endl;#endif int oldcurpos=curpos; c+=j; const QCString name( scan_identifier( c) ); if ( name.isEmpty() ) break; while (*c && isspace(*c)) c++; if (*c && *c=='"') c++; single_escape=true; curpos=0; char* result=0; c=scan_troff(c,1,&result); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=curpos; def.m_output=result; s_stringDefinitionMap.insert(name,def); } else { if (mode) { // .ds Defining String (*it).m_length=curpos; (*it).m_output=result; } else { // .as Appending String (*it).m_length+=curpos; (*it).m_output+=result; } } delete[] result; single_escape=false; curpos=oldcurpos;#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .ds/.as" << endl;#endif break; } case REQ_br: // groff(7) "line BReak" { if (still_dd) out_html("<DD>"); // ### VERIFY (does not look like generating good HTML) else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: // groff(7) "reset non-break Control character" (2 means non-break) { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: // groff(7) "reset Control Character" { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: // groff (7) "CEnter" { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && qstrncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: // groff(7) "reset Escape Character" { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: // groff(7) "turn Escape character Off" { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: // groff(7) "EXit" { return 0; break; } case REQ_fc: // groff(7) "set Field and pad Character" { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: // groff(7) "FIll" { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: // groff(7) "previous FonT" { c=c+j; if (*c=='\n') out_html(set_font("R"));#if 0 else { // ### FIXME if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(set_font(fn)); } else { out_html(set_font(*c)); c++; } }#endif c=skip_till_newline(c); break; } case REQ_el: // groff(7) "ELse" { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: // groff(7) "If with Else" /* .ie c anything : then part of if else */ case REQ_if: // groff(7) "IF" { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: // groff(7) "IGnore" { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && qstrncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: // groff(7) "No Filling" { if (fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: // groff(7) "previous Point Size" { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: // groff(7) "SKip one line" { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: // groff(7) "Include SOurce file" { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "man2html: unable to open or read file %s.\n", h);#else kdDebug(7107) << "Unable to open or read file: .so " << (h) << endl;#endif out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: // gorff(7) "set TAbulators" { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: // groff(7) "Temporary Indent" { /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html("&nbsp;"); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: // groff(7) "TerMinal" ### TODO: what are useful uses for it { c=c+j; h=c; while (*c!='\n') c++; *c='\0';#ifdef SIMPLE_MAN2HTML fprintf(stderr,"%s\n", h);#else kdDebug(7107) << ".tm " << (h) << endl;#endif *c='\n'; break; } case REQ_B: // man(7) "Bold" mode=1; case REQ_I: // man(7) "Italic" { /* parse one line in a certain font */ out_html( set_font( mode?"B":"I" ) ); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font("R")); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(set_font("R")); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(set_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'R'; // ### FIXME out_html(set_font(font[i&1])); out_html(")"); out_html(set_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'R'; // ### FIXME c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(set_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=true; c[0]='B'; c[1]='I'; out_html(set_font("R")); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) * indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(set_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(set_font("R")); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: // man(7) "Default Tabulators" { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: // man(7) "Ident Paragraph" { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: // man(7) "hanging Tag Paragraph" { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=true; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: // "INdex" ### TODO: where is it defined? { /* general index */ c=skip_till_newline(c); break; } case REQ_P: // man(7) "Paragraph" case REQ_LP:// man(7) "Paragraph" case REQ_PP:// man(7) "Paragraph; reset Prevailing indent" { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: // man(7) "Hanging indent Paragraph" { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=true; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: // man(7) "Paragraph Distance" { c=skip_till_newline(c); break; } case REQ_Rs: // mdoc(7) "Relative margin Start" case REQ_RS: // man(7) "Relative margin Start" { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: // mdoc(7) "Relative margin End" case REQ_RE: // man(7) "Relative margin End" { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: // man(7) "Small; Bold" { out_html(set_font('B')); out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c+j, 1, NULL); out_html("</small>"); out_html(set_font('R')); break; } case REQ_SM: // man(7) "SMall" { c=c+j; if (*c=='\n') c++; out_html("<small>"); trans_char(c,'"','\a'); // ### VERIFY c=scan_troff(c,1,NULL); out_html("</small>"); break; } case REQ_Ss: // mdoc(7) "Sub Section" mandoc_command = 1; case REQ_SS: // mdoc(7) "Sub Section" mode=true; case REQ_Sh: // mdoc(7) "Sub Header" /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(set_font("R")); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = qstrncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: // mdoc(7) { // reference to a section header out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: // ### TODO where is it defined? (tbl?) { c=scan_table(c); break; } case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: // man(7) "Title Header" { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); // ### TODO: the page should be displayed even if it is "anonymous" (words==0) if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][qstrlen(wordlist[i])-1] == '\007') wordlist[i][qstrlen(wordlist[i])-1] = 0; } output_possible=true; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"ROFF Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else {#ifdef SIMPLE_MAN2HTML fprintf(stderr, "%s", ".TH found but output not possible");#else kdWarning(7107) << ".TH found but output not possible" << endl;#endif c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: // mdoc(7) { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(set_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=qstrlen(c2); out_html(c2); out_html(set_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: // groff(7) "ReMove" /* .rm xx : Remove request, macro or string */ mode=true; case REQ_rn: // groff(7) "ReName" /* .rn xx yy : Rename request, macro or string xx to yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rm/.rn" << endl;#endif c+=j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } QCString name2; if ( !mode ) { while (*c && isspace(*c) && *c!='\n') ++c; name2 = scan_identifier( c ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to rename: " << endl;#endif break; } } c=skip_till_newline(c); QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to rename or remove: " << name << endl;#endif } else { if (mode) { // .rm ReMove s_stringDefinitionMap.remove(name); // ### QT4: removeAll } else { // .rn ReName StringDefinition def=(*it); s_stringDefinitionMap.remove(name); // ### QT4: removeAll s_stringDefinitionMap.insert(name2,def); } }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rm/.rn" << endl;#endif break; } case REQ_nx: // ### TODO in man(7) it is "No filling", not "next file" /* .nx filename : next file. */ case REQ_in: // groff(7) "INdent" { /* .in +-N : Indent */ c=skip_till_newline(c); break; } case REQ_nr: // groff(7) "Number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .nr" << endl;#endif c += j; const QCString name( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty name for register variable" << endl;#endif break; } while ( *c && ( *c==' ' || *c=='\t' ) ) c++; int sign = 0; if ( *c && ( *c == '+' || *c == '-' ) ) { if ( *c == '+' ) sign = 1; else if ( *c == '-' ) sign = -1; } int value = 0; int increment = 0; c=scan_expression( c, &value ); if ( *c && *c!='\n') { while ( *c && ( *c==' ' || *c=='\t' ) ) c++; c=scan_expression( c, &increment ); } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) { if ( sign < 1 ) value = -value; NumberDefinition def( value, increment ); s_numberDefinitionMap.insert( name, def ); } else { if ( sign > 0 ) (*it).m_value += value; else if ( sign < 0 ) (*it).m_value += - value; else (*it).m_value = value; (*it).m_increment = increment; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .nr" << endl;#endif break; } case REQ_am: // groff(7) "Append Macro" /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=true; case REQ_de: // groff(7) "DEfine macro" /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Start .am/.de" << endl;#endif c+=j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *nameStart = wordlist[0]; c = nameStart; while (*c && (*c != ' ') && (*c != '\n')) c++; *c = '\0'; const QCString name(nameStart); QCString endmacro; if (words == 1) { endmacro=".."; } else { endmacro='.'; c = wordlist[1]; while (*c && (*c != ' ') && (*c != '\n')) endmacro+=*c++; } c = next_line; sl=c; const int length=qstrlen(endmacro); while (*c && qstrncmp(c,endmacro,length)) c=skip_till_newline(c); QCString macro; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { macro+='\\'; sl++; } else macro+=*sl; sl++; } QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name); if (it==s_stringDefinitionMap.end()) { StringDefinition def; def.m_length=0; def.m_output=macro; s_stringDefinitionMap.insert(name,def); } else if (mode) { // .am Append Macro (*it).m_length=0; // It could be formerly a string if ((*it).m_output.right(1)!='\n') (*it).m_output+='\n'; (*it).m_output+=macro; } else { // .de DEfine macro (*it).m_length=0; // It could be formerly a string (*it).m_output=macro; } c=skip_till_newline(c);#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "End .am/.de" << endl;#endif break; } case REQ_Bl: // mdoc(7) "Begin List" { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: // mdoc(7) "End List" { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: // mdoc(7) "list ITem" { c=c+j; if (qstrncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(set_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(set_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: // mdoc(7) "Operating System" { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Bt: // mdoc(7) "Beta Test" { trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; } case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&amp;T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ { c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; } case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(set_font("R")); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ { if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(set_font("R")); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_Be: /* mdoc(7) */ { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(set_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pp: /* mdoc(7) */ { if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"&lt;","&gt;"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"&ldquo;","&rdquo;"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,"&quot;","&quot;"); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"&lsquo;","&rsquo;"); break; case REQ_Op: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Oo: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; } case REQ_Oc: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; } case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Em: /* mdoc(7) */ { out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ { /* parse one line in italics */ out_html(set_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nd: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(set_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(set_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ { /* parse one line in bold */ out_html(set_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ { trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(set_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(set_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: { c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; } case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: { c=c+j; out_html(set_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(set_font('R')); if (fillout) curpos++; else curpos=0; break; } case REQ_UR: // ### FIXME man(7) "URl" { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME man(7) "Url End" { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME man(7) "Url Named anchor" { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\"></a>"); } c=newc; break; } case REQ_nroff: // groff(7) "NROFF mode" mode = true; case REQ_troff: // groff(7) "TROFF mode" { s_nroff = mode; c+=j; c = skip_till_newline(c); } case REQ_als: // groff(7) "ALias String" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .als" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination string to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c=skip_till_newline(c); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination string to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rn) QMap<QCString,StringDefinition>::iterator it=s_stringDefinitionMap.find(name2); if (it==s_stringDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { StringDefinition def=(*it); s_stringDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .als" << endl;#endif break; } case REQ_rr: // groff(7) "Remove number Register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rr" << endl;#endif c += j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin string to remove/rename: " << endl;#endif break; } c = skip_till_newline( c ); QMap <QCString, NumberDefinition>::iterator it = s_numberDefinitionMap.find( name ); if ( it == s_numberDefinitionMap.end() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: trying to remove inexistant number register: " << endl;#endif } else { s_numberDefinitionMap.remove( name ); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rr" << endl;#endif break; } case REQ_rnn: // groff(7) "ReName Number register" {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .rnn" << endl;#endif c+=j; const QCString name ( scan_identifier ( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin to remove/rename number register" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier ( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination to rename number register " << endl;#endif break; } c = skip_till_newline( c ); QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find number register to rename: " << name << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.remove(name); // ### QT4: removeAll s_numberDefinitionMap.insert(name2,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .rnn" << endl;#endif break; } case REQ_aln: // groff(7) "ALias Number Register" { /* * Note an alias is supposed to be something like a hard link * However to make it simplier, we only copy the string. */ // Be careful: unlike .rnn, the destination is first, origin is second#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "start .aln" << endl;#endif c+=j; const QCString name ( scan_identifier( c ) ); if ( name.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty destination number register to alias" << endl;#endif break; } while (*c && isspace(*c) && *c!='\n') ++c; const QCString name2 ( scan_identifier( c ) ); if ( name2.isEmpty() ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: empty origin number register to alias" << endl;#endif break; }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "Alias " << name2 << " to " << name << endl;#endif c = skip_till_newline( c ); if ( name == name2 ) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: same origin and destination number register to alias: " << name << endl;#endif break; } // Second parametr is origin (unlike in .rnn) QMap<QCString,NumberDefinition>::iterator it=s_numberDefinitionMap.find(name2); if (it==s_numberDefinitionMap.end()) {#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "EXCEPTION: cannot find string to make alias: " << name2 << endl;#endif } else { NumberDefinition def=(*it); s_numberDefinitionMap.insert(name,def); }#ifndef SIMPLE_MAN2HTML kdDebug(7107) << "end .aln" << endl;#endif break; } case REQ_shift: // groff(7) "SHIFT parameter" { c+=j; h=c; while (*h && *h!='\n' && isdigit(*h) ) ++h; const char tempchar = *h; *h = 0; const QCString number = c; *h = tempchar; c = skip_till_newline( h ); unsigned int result = 1; // Numbers of shifts to do if ( !number.isEmpty() ) { bool ok = false; result = number.toUInt(&ok); if ( !ok || result < 1 ) result = 1; } for ( unsigned int num = 0; num < result; ++num ) { if ( !s_argumentList.isEmpty() ) s_argumentList.pop_front(); } break; } case REQ_while: // groff(7) "WHILE loop" { request_while( c, j, mandoc_command ); break; } default: { if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; qstrncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(set_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;}
3322 /local/tlutelli/issta_data/temp/c/2005_temp/2005/3322/02847f87e5aaf12517fc3417ea75ced7e8699eff/man2html.cpp/clean/kioslave/man/man2html.cpp