htdocs: Use also GeSHi styles for example code
This commit is contained in:
parent
0d9640eb10
commit
1eb36e9810
|
@ -55,40 +55,40 @@ void f()
|
|||
<h3>Examples</h3>
|
||||
<p>This code can be copy and pasted in the edit box above.</p>
|
||||
<h4>NULL pointers</h4>
|
||||
<pre class="code">void f1(struct fred_t *p)
|
||||
{
|
||||
<em>// dereference p and then check if it's NULL</em>
|
||||
int x = p->x;
|
||||
if (p)
|
||||
do_something(x);
|
||||
}
|
||||
<pre class="cpp geshicode"><span class="kw4">void</span> f1<span class="br0">(</span><span class="kw4">struct</span> fred_t <span class="sy2">*</span>p<span class="br0">)</span>
|
||||
<span class="br0">{</span>
|
||||
<span class="co1">// dereference p and then check if it's NULL</span>
|
||||
<span class="kw4">int</span> x <span class="sy1">=</span> p<span class="sy2">-</span><span class="sy1">></span>x<span class="sy4">;</span>
|
||||
<span class="kw1">if</span> <span class="br0">(</span>p<span class="br0">)</span>
|
||||
do_something<span class="br0">(</span>x<span class="br0">)</span><span class="sy4">;</span>
|
||||
<span class="br0">}</span>
|
||||
|
||||
void f2()
|
||||
{
|
||||
const char *p = NULL;
|
||||
for (int i = 0; str[i] != '\0'; i++)
|
||||
{
|
||||
if (str[i] == ' ')
|
||||
{
|
||||
p = str + i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
<span class="kw4">void</span> f2<span class="br0">(</span><span class="br0">)</span>
|
||||
<span class="br0">{</span>
|
||||
<span class="kw4">const</span> <span class="kw4">char</span> <span class="sy2">*</span>p <span class="sy1">=</span> <span class="kw2">NULL</span><span class="sy4">;</span>
|
||||
<span class="kw1">for</span> <span class="br0">(</span><span class="kw4">int</span> i <span class="sy1">=</span> <span class="nu0">0</span><span class="sy4">;</span> str<span class="br0">[</span>i<span class="br0">]</span> <span class="sy3">!</span><span class="sy1">=</span> <span class="st0">'<span class="es5">\0</span>'</span><span class="sy4">;</span> i<span class="sy2">++</span><span class="br0">)</span>
|
||||
<span class="br0">{</span>
|
||||
<span class="kw1">if</span> <span class="br0">(</span>str<span class="br0">[</span>i<span class="br0">]</span> <span class="sy1">==</span> <span class="st0">' '</span><span class="br0">)</span>
|
||||
<span class="br0">{</span>
|
||||
p <span class="sy1">=</span> str <span class="sy2">+</span> i<span class="sy4">;</span>
|
||||
<span class="kw1">break</span><span class="sy4">;</span>
|
||||
<span class="br0">}</span>
|
||||
<span class="br0">}</span>
|
||||
|
||||
<em>// p is NULL if str doesn't have a space. If str always has a</em>
|
||||
<em>// a space then the condition (str[i] != '\0') would be redundant</em>
|
||||
return p[1];
|
||||
}
|
||||
<span class="co1">// p is NULL if str doesn't have a space. If str always has a</span>
|
||||
<span class="co1">// a space then the condition (str[i] != '\0') would be redundant</span>
|
||||
<span class="kw1">return</span> p<span class="br0">[</span><span class="nu0">1</span><span class="br0">]</span><span class="sy4">;</span>
|
||||
<span class="br0">}</span>
|
||||
|
||||
void f3(int a)
|
||||
{
|
||||
struct fred_t *p = NULL;
|
||||
if (a == 1)
|
||||
p = fred1;
|
||||
<span class="kw4">void</span> f3<span class="br0">(</span><span class="kw4">int</span> a<span class="br0">)</span>
|
||||
<span class="br0">{</span>
|
||||
<span class="kw4">struct</span> fred_t <span class="sy2">*</span>p <span class="sy1">=</span> <span class="kw2">NULL</span><span class="sy4">;</span>
|
||||
<span class="kw1">if</span> <span class="br0">(</span>a <span class="sy1">==</span> <span class="nu0">1</span><span class="br0">)</span>
|
||||
p <span class="sy1">=</span> fred1<span class="sy4">;</span>
|
||||
|
||||
<em>// if a is not 1 then p is NULL</em>
|
||||
p->x = 0;
|
||||
}</pre>
|
||||
<span class="co1">// if a is not 1 then p is NULL</span>
|
||||
p<span class="sy2">-</span><span class="sy1">></span>x <span class="sy1">=</span> <span class="nu0">0</span><span class="sy4">;</span>
|
||||
<span class="br0">}</span></pre>
|
||||
</div> <!-- .wrap -->
|
||||
</div> <!-- #content -->
|
||||
</body>
|
||||
|
|
|
@ -1,12 +1,4 @@
|
|||
/* Source Code */
|
||||
pre.code {
|
||||
padding: .5em;
|
||||
background: #f7f7f7;
|
||||
border: 1px solid #e2e2e2;
|
||||
}
|
||||
pre.code em {
|
||||
color: green;
|
||||
}
|
||||
.geshicode {
|
||||
padding: .5em;
|
||||
background: #f7f7f7;
|
||||
|
|
|
@ -1 +1 @@
|
|||
pre.code{padding:.5em;background:#f7f7f7;border:1px solid #e2e2e2}pre.code em{color:green}.geshicode{padding:.5em;background:#f7f7f7;border:1px solid #e2e2e2}#resultsTable{border-collapse:collapse}#resultsTable th{padding:.25em;text-align:left;background:#e2e2e2;border:1px solid #e2e2e2}#resultsTable td{padding:.25em;background:#f7f7f7;border:1px solid #e2e2e2}#resultsTable .center{text-align:center}.maxChars{margin-left:2em;color:#888;font-size:smaller}.cpp.geshicode .de1,.cpp.geshicode .de2{font:normal normal 1em/1.2em monospace;margin:0;padding:0;background:0;vertical-align:top}.cpp.geshicode{font-family:monospace}.cpp.geshicode .imp{font-weight:700;color:red}.cpp.geshicode li,.cpp.geshicode .li1{font-weight:400;vertical-align:top}.cpp.geshicode .ln{width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;color:#999}.cpp.geshicode .kw1{color:#00f}.cpp.geshicode .kw2{color:#00f}.cpp.geshicode .kw3{color:#00d}.cpp.geshicode .kw4{color:#00f}.cpp.geshicode .co1{color:#666}.cpp.geshicode .co2{color:#390}.cpp.geshicode .coMULTI{color:red;font-style:italic}.cpp.geshicode .es0{color:#009;font-weight:700}.cpp.geshicode .es1{color:#009;font-weight:700}.cpp.geshicode .es2{color:#609;font-weight:700}.cpp.geshicode .es3{color:#609;font-weight:700}.cpp.geshicode .es4{color:#609;font-weight:700}.cpp.geshicode .es5{color:#069;font-weight:700}.cpp.geshicode .br0{color:#008000}.cpp.geshicode .sy0{color:#008000}.cpp.geshicode .sy1{color:#000080}.cpp.geshicode .sy2{color:#000040}.cpp.geshicode .sy3{color:#000040}.cpp.geshicode .sy4{color:#008080}.cpp.geshicode .st0{color:red}.cpp.geshicode .nu0{color:#00d}.cpp.geshicode .nu6{color:#208080}.cpp.geshicode .nu8{color:#208080}.cpp.geshicode .nu12{color:#208080}.cpp.geshicode .nu16{color:#800080}.cpp.geshicode .nu17{color:#800080}.cpp.geshicode .nu18{color:#800080}.cpp.geshicode .nu19{color:#800080}.cpp.geshicode .me1{color:#078}.cpp.geshicode .me2{color:#078}.cpp.geshicode span.xtra{display:block}
|
||||
.geshicode{padding:.5em;background:#f7f7f7;border:1px solid #e2e2e2}#resultsTable{border-collapse:collapse}#resultsTable th{padding:.25em;text-align:left;background:#e2e2e2;border:1px solid #e2e2e2}#resultsTable td{padding:.25em;background:#f7f7f7;border:1px solid #e2e2e2}#resultsTable .center{text-align:center}.maxChars{margin-left:2em;color:#888;font-size:smaller}.cpp.geshicode .de1,.cpp.geshicode .de2{font:normal normal 1em/1.2em monospace;margin:0;padding:0;background:0;vertical-align:top}.cpp.geshicode{font-family:monospace}.cpp.geshicode .imp{font-weight:700;color:red}.cpp.geshicode li,.cpp.geshicode .li1{font-weight:400;vertical-align:top}.cpp.geshicode .ln{width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;color:#999}.cpp.geshicode .kw1{color:#00f}.cpp.geshicode .kw2{color:#00f}.cpp.geshicode .kw3{color:#00d}.cpp.geshicode .kw4{color:#00f}.cpp.geshicode .co1{color:#666}.cpp.geshicode .co2{color:#390}.cpp.geshicode .coMULTI{color:red;font-style:italic}.cpp.geshicode .es0{color:#009;font-weight:700}.cpp.geshicode .es1{color:#009;font-weight:700}.cpp.geshicode .es2{color:#609;font-weight:700}.cpp.geshicode .es3{color:#609;font-weight:700}.cpp.geshicode .es4{color:#609;font-weight:700}.cpp.geshicode .es5{color:#069;font-weight:700}.cpp.geshicode .br0{color:#008000}.cpp.geshicode .sy0{color:#008000}.cpp.geshicode .sy1{color:#000080}.cpp.geshicode .sy2{color:#000040}.cpp.geshicode .sy3{color:#000040}.cpp.geshicode .sy4{color:#008080}.cpp.geshicode .st0{color:red}.cpp.geshicode .nu0{color:#00d}.cpp.geshicode .nu6{color:#208080}.cpp.geshicode .nu8{color:#208080}.cpp.geshicode .nu12{color:#208080}.cpp.geshicode .nu16{color:#800080}.cpp.geshicode .nu17{color:#800080}.cpp.geshicode .nu18{color:#800080}.cpp.geshicode .nu19{color:#800080}.cpp.geshicode .me1{color:#078}.cpp.geshicode .me2{color:#078}.cpp.geshicode span.xtra{display:block}
|
Loading…
Reference in New Issue