source: trunk/src/gpu/shader.cpp @ 1259

Last change on this file since 1259 was 1259, checked in by sam, 9 years ago

gpu: add methods to send mat2 and mat3 matrices to the shader.

  • Property svn:keywords set to Id
File size: 19.2 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <cmath>
16#include <cstring>
17#include <cstdio>
18
19#ifdef WIN32
20#   define WIN32_LEAN_AND_MEAN
21#   include <windows.h>
22#   if defined USE_D3D9
23#       include <algorithm>
24        using std::min;
25        using std::max;
26#       include <d3d9.h>
27#       include <d3dx9shader.h>
28#   endif
29#endif
30
31#include "core.h"
32#include "lolgl.h"
33
34using namespace std;
35
36#if defined USE_D3D9
37extern IDirect3DDevice9 *g_d3ddevice;
38#elif defined _XBOX
39extern D3DDevice *g_d3ddevice;
40#endif
41
42namespace lol
43{
44
45/*
46 * Shader implementation class
47 */
48
49class ShaderData
50{
51    friend class Shader;
52
53private:
54#if defined USE_D3D9
55    IDirect3DVertexShader9 *vert_shader;
56    IDirect3DPixelShader9 *frag_shader;
57    ID3DXConstantTable *vert_table, *frag_table;
58#elif defined _XBOX
59    D3DVertexShader *vert_shader;
60    D3DPixelShader *frag_shader;
61    ID3DXConstantTable *vert_table, *frag_table;
62#elif !defined __CELLOS_LV2__
63    GLuint prog_id, vert_id, frag_id;
64#else
65    CGprogram vert_id, frag_id;
66#endif
67    uint32_t vert_crc, frag_crc;
68
69    /* Shader patcher */
70    static int GetVersion();
71    static void Patch(char *dst, char const *vert, char const *frag);
72
73    /* Global shader cache */
74    static Shader *shaders[];
75    static int nshaders;
76};
77
78Shader *ShaderData::shaders[256];
79int ShaderData::nshaders = 0;
80
81/*
82 * Public Shader class
83 */
84
85Shader *Shader::Create(char const *vert, char const *frag)
86{
87    uint32_t new_vert_crc = Hash::Crc32(vert);
88    uint32_t new_frag_crc = Hash::Crc32(frag);
89
90    for (int n = 0; n < ShaderData::nshaders; n++)
91    {
92        if (ShaderData::shaders[n]->data->vert_crc == new_vert_crc
93             && ShaderData::shaders[n]->data->frag_crc == new_frag_crc)
94            return ShaderData::shaders[n];
95    }
96
97    Shader *ret = new Shader(vert, frag);
98    ShaderData::shaders[ShaderData::nshaders] = ret;
99    ShaderData::nshaders++;
100    return ret;
101}
102
103void Shader::Destroy(Shader *shader)
104{
105    /* XXX: do nothing! the shader should remain in cache */
106    (void)shader;
107}
108
109Shader::Shader(char const *vert, char const *frag)
110  : data(new ShaderData())
111{
112#if defined USE_D3D9 || defined _XBOX
113    ID3DXBuffer *shader_code, *error_msg;
114    HRESULT hr;
115#elif !defined __CELLOS_LV2__
116    char buf[4096], errbuf[4096];
117    char const *shader = buf;
118    GLint status;
119    GLsizei len;
120#else
121    /* Initialise the runtime shader compiler. FIXME: this needs only
122     * to be done once. */
123    cgRTCgcInit();
124#endif
125
126    /* Compile vertex shader */
127    data->vert_crc = Hash::Crc32(vert);
128#if defined USE_D3D9 || defined _XBOX
129    hr = D3DXCompileShader(vert, (UINT)strlen(vert), NULL, NULL, "main",
130                           "vs_2_0", 0, &shader_code, &error_msg,
131                           &data->vert_table);
132    if (FAILED(hr))
133    {
134        Log::Error("failed to compile vertex shader: %s",
135                   error_msg ? error_msg->GetBufferPointer() : "error");
136        Log::Error("shader source:\n%s\n", vert);
137    }
138    g_d3ddevice->CreateVertexShader((DWORD *)shader_code->GetBufferPointer(),
139                                    &data->vert_shader);
140    shader_code->Release();
141#elif !defined __CELLOS_LV2__
142    ShaderData::Patch(buf, vert, NULL);
143    data->vert_id = glCreateShader(GL_VERTEX_SHADER);
144    glShaderSource(data->vert_id, 1, &shader, NULL);
145    glCompileShader(data->vert_id);
146
147    glGetShaderiv(data->vert_id, GL_COMPILE_STATUS, &status);
148    if (status != GL_TRUE)
149    {
150        glGetShaderInfoLog(data->vert_id, sizeof(errbuf), &len, errbuf);
151        Log::Error("failed to compile vertex shader: %s", errbuf);
152        Log::Error("shader source:\n%s\n", buf);
153    }
154#else
155    data->vert_id = cgCreateProgram(cgCreateContext(), CG_SOURCE, vert,
156                                    cgGLGetLatestProfile(CG_GL_VERTEX),
157                                    NULL, NULL);
158    if (data->vert_id == NULL)
159    {
160        Log::Error("failed to compile vertex shader");
161        Log::Error("shader source:\n%s\n", vert);
162    }
163#endif
164
165    /* Compile fragment shader */
166    data->frag_crc = Hash::Crc32(frag);
167#if defined USE_D3D9 || defined _XBOX
168    hr = D3DXCompileShader(frag, (UINT)strlen(frag), NULL, NULL, "main",
169                           "ps_2_0", 0, &shader_code, &error_msg,
170                           &data->frag_table);
171    if (FAILED(hr))
172    {
173        Log::Error("failed to compile fragment shader: %s",
174                   error_msg ? error_msg->GetBufferPointer() : "error");
175        Log::Error("shader source:\n%s\n", frag);
176    }
177    g_d3ddevice->CreatePixelShader((DWORD *)shader_code->GetBufferPointer(),
178                                   &data->frag_shader);
179    shader_code->Release();
180#elif !defined __CELLOS_LV2__
181    ShaderData::Patch(buf, NULL, frag);
182    data->frag_id = glCreateShader(GL_FRAGMENT_SHADER);
183    glShaderSource(data->frag_id, 1, &shader, NULL);
184    glCompileShader(data->frag_id);
185
186    glGetShaderiv(data->frag_id, GL_COMPILE_STATUS, &status);
187    if (status != GL_TRUE)
188    {
189        glGetShaderInfoLog(data->frag_id, sizeof(errbuf), &len, errbuf);
190        Log::Error("failed to compile fragment shader: %s", errbuf);
191        Log::Error("shader source:\n%s\n", buf);
192    }
193#else
194    data->frag_id = cgCreateProgram(cgCreateContext(), CG_SOURCE, frag,
195                                    cgGLGetLatestProfile(CG_GL_FRAGMENT),
196                                    NULL, NULL);
197    if (data->frag_id == NULL)
198    {
199        Log::Error("failed to compile fragment shader");
200        Log::Error("shader source:\n%s\n", frag);
201    }
202#endif
203
204#if defined USE_D3D9 || defined _XBOX
205    /* FIXME: this is only debug code, we don't need it. */
206    D3DXCONSTANTTABLE_DESC desc;
207    data->frag_table->GetDesc(&desc);
208    for (int i = 0; i < desc.Constants; i++)
209    {
210        D3DXCONSTANT_DESC cdesc;
211        UINT count = 1;
212        D3DXHANDLE h = data->frag_table->GetConstant(NULL, i);
213        data->frag_table->GetConstantDesc(h, &cdesc, &count);
214    }
215    data->vert_table->GetDesc(&desc);
216    for (int i = 0; i < desc.Constants; i++)
217    {
218        D3DXCONSTANT_DESC cdesc;
219        UINT count = 1;
220        D3DXHANDLE h = data->vert_table->GetConstant(NULL, i);
221        data->frag_table->GetConstantDesc(h, &cdesc, &count);
222    }
223#elif !defined __CELLOS_LV2__
224    /* Create program */
225    data->prog_id = glCreateProgram();
226    glAttachShader(data->prog_id, data->vert_id);
227    glAttachShader(data->prog_id, data->frag_id);
228
229    glLinkProgram(data->prog_id);
230    glValidateProgram(data->prog_id);
231#endif
232}
233
234ShaderAttrib Shader::GetAttribLocation(char const *attr,
235                                       VertexUsage usage, int index) const
236{
237    ShaderAttrib ret;
238    ret.m_flags = (uint64_t)(uint16_t)usage << 16;
239    ret.m_flags |= (uint64_t)(uint16_t)index;
240#if defined USE_D3D9 || defined _XBOX
241#elif !defined __CELLOS_LV2__
242    ret.m_flags |= (uint64_t)
243                  (uint32_t)glGetAttribLocation(data->prog_id, attr) << 32;
244#else
245    /* FIXME: can we do this at all on the PS3? */
246#endif
247    return ret;
248}
249
250ShaderUniform Shader::GetUniformLocation(char const *uni) const
251{
252    ShaderUniform ret;
253#if defined USE_D3D9 || defined _XBOX
254    /* Global variables are prefixed with "$" */
255    char tmpname[128];
256    sprintf(tmpname, "$%s", uni);
257    D3DXCONSTANT_DESC cdesc;
258    D3DXHANDLE hr;
259    UINT count;
260
261    count = 0;
262    hr = data->frag_table->GetConstantByName(NULL, tmpname);
263    if (hr)
264        data->frag_table->GetConstantDesc(hr, &cdesc, &count);
265    if (count)
266    {
267        ret.frag = cdesc.RegisterIndex;
268        ret.flags |= 1;
269    }
270
271    count = 0;
272    hr = data->vert_table->GetConstantByName(NULL, tmpname);
273    if (hr)
274        data->vert_table->GetConstantDesc(hr, &cdesc, &count);
275    if (count)
276    {
277        ret.vert = cdesc.RegisterIndex;
278        ret.flags |= 2;
279    }
280#elif !defined __CELLOS_LV2__
281    ret.frag = (uintptr_t)glGetUniformLocation(data->prog_id, uni);
282    ret.vert = 0;
283#else
284    ret.frag = (uintptr_t)cgGetNamedParameter(data->frag_id, uni);
285    ret.vert = (uintptr_t)cgGetNamedParameter(data->vert_id, uni);
286#endif
287    return ret;
288}
289
290void Shader::SetUniform(ShaderUniform const &uni, int i)
291{
292#if defined USE_D3D9 || defined _XBOX
293    SetUniform(uni, ivec4(i, 0, 0, 0));
294#elif !defined __CELLOS_LV2__
295    glUniform1i(uni.frag, i);
296#else
297    /* FIXME: does this exist at all? */
298    //cgGLSetParameter1i((CGparameter)uni.frag, i);
299#endif
300}
301
302void Shader::SetUniform(ShaderUniform const &uni, ivec2 const &v)
303{
304#if defined USE_D3D9 || defined _XBOX
305    SetUniform(uni, ivec4(v, 0, 0));
306#elif !defined __CELLOS_LV2__
307    glUniform2i(uni.frag, v.x, v.y);
308#else
309    /* FIXME: does this exist at all? */
310#endif
311}
312
313void Shader::SetUniform(ShaderUniform const &uni, ivec3 const &v)
314{
315#if defined USE_D3D9 || defined _XBOX
316    SetUniform(uni, ivec4(v, 0));
317#elif !defined __CELLOS_LV2__
318    glUniform3i(uni.frag, v.x, v.y, v.z);
319#else
320    /* FIXME: does this exist at all? */
321#endif
322}
323
324void Shader::SetUniform(ShaderUniform const &uni, ivec4 const &v)
325{
326#if defined USE_D3D9 || defined _XBOX
327    if (uni.flags & 1)
328        g_d3ddevice->SetPixelShaderConstantI((UINT)uni.frag, &v[0], 1);
329    if (uni.flags & 2)
330        g_d3ddevice->SetVertexShaderConstantI((UINT)uni.vert, &v[0], 1);
331#elif !defined __CELLOS_LV2__
332    glUniform4i(uni.frag, v.x, v.y, v.z, v.w);
333#else
334    /* FIXME: does this exist at all? */
335#endif
336}
337
338void Shader::SetUniform(ShaderUniform const &uni, float f)
339{
340#if defined USE_D3D9 || defined _XBOX
341    SetUniform(uni, vec4(f, 0, 0, 0));
342#elif !defined __CELLOS_LV2__
343    glUniform1f(uni.frag, f);
344#else
345    if (uni.frag)
346        cgGLSetParameter1f((CGparameter)uni.frag, f);
347    if (uni.vert)
348        cgGLSetParameter1f((CGparameter)uni.vert, f);
349#endif
350}
351
352void Shader::SetUniform(ShaderUniform const &uni, vec2 const &v)
353{
354#if defined USE_D3D9 || defined _XBOX
355    SetUniform(uni, vec4(v, 0, 0));
356#elif !defined __CELLOS_LV2__
357    glUniform2f(uni.frag, v.x, v.y);
358#else
359    if (uni.frag)
360        cgGLSetParameter2f((CGparameter)uni.frag, v.x, v.y);
361    if (uni.vert)
362        cgGLSetParameter2f((CGparameter)uni.vert, v.x, v.y);
363#endif
364}
365
366void Shader::SetUniform(ShaderUniform const &uni, vec3 const &v)
367{
368#if defined USE_D3D9 || defined _XBOX
369    SetUniform(uni, vec4(v, 0));
370#elif !defined __CELLOS_LV2__
371    glUniform3f(uni.frag, v.x, v.y, v.z);
372#else
373    if (uni.frag)
374        cgGLSetParameter3f((CGparameter)uni.frag, v.x, v.y, v.z);
375    if (uni.vert)
376        cgGLSetParameter3f((CGparameter)uni.vert, v.x, v.y, v.z);
377#endif
378}
379
380void Shader::SetUniform(ShaderUniform const &uni, vec4 const &v)
381{
382#if defined USE_D3D9 || defined _XBOX
383    if (uni.flags & 1)
384        g_d3ddevice->SetPixelShaderConstantF((UINT)uni.frag, &v[0], 1);
385    if (uni.flags & 2)
386        g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert, &v[0], 1);
387#elif !defined __CELLOS_LV2__
388    glUniform4f(uni.frag, v.x, v.y, v.z, v.w);
389#else
390    /* FIXME: use the array versions of these functions */
391    if (uni.frag)
392        cgGLSetParameter4f((CGparameter)uni.frag, v.x, v.y, v.z, v.w);
393    if (uni.vert)
394        cgGLSetParameter4f((CGparameter)uni.vert, v.x, v.y, v.z, v.w);
395#endif
396}
397
398void Shader::SetUniform(ShaderUniform const &uni, mat2 const &m)
399{
400#if defined USE_D3D9 || defined _XBOX
401    if (uni.flags & 1)
402        g_d3ddevice->SetPixelShaderConstantF((UINT)uni.frag, &m[0][0], 1);
403    if (uni.flags & 2)
404        g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert, &m[0][0], 1);
405#elif !defined __CELLOS_LV2__
406    glUniformMatrix2fv(uni.frag, 1, GL_FALSE, &m[0][0]);
407#else
408    /* Not implemented */
409    Abort();
410#endif
411}
412
413void Shader::SetUniform(ShaderUniform const &uni, mat3 const &m)
414{
415#if defined USE_D3D9 || defined _XBOX
416    /* FIXME: does this work at all? */
417    if (uni.flags & 1)
418        g_d3ddevice->SetPixelShaderConstantF((UINT)uni.frag, &m[0][0], 3);
419    if (uni.flags & 2)
420        g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert, &m[0][0], 3);
421#elif !defined __CELLOS_LV2__
422    glUniformMatrix3fv(uni.frag, 1, GL_FALSE, &m[0][0]);
423#else
424    /* FIXME: not implemented */
425    Abort();
426#endif
427}
428
429void Shader::SetUniform(ShaderUniform const &uni, mat4 const &m)
430{
431#if defined USE_D3D9 || defined _XBOX
432    if (uni.flags & 1)
433        g_d3ddevice->SetPixelShaderConstantF((UINT)uni.frag, &m[0][0], 4);
434    if (uni.flags & 2)
435        g_d3ddevice->SetVertexShaderConstantF((UINT)uni.vert, &m[0][0], 4);
436#elif !defined __CELLOS_LV2__
437    glUniformMatrix4fv(uni.frag, 1, GL_FALSE, &m[0][0]);
438#else
439    if (uni.frag)
440        cgGLSetMatrixParameterfc((CGparameter)uni.frag, &m[0][0]);
441    if (uni.vert)
442        cgGLSetMatrixParameterfc((CGparameter)uni.vert, &m[0][0]);
443#endif
444}
445
446void Shader::Bind() const
447{
448#if defined USE_D3D9 || defined _XBOX
449    HRESULT hr;
450    hr = g_d3ddevice->SetVertexShader(data->vert_shader);
451    hr = g_d3ddevice->SetPixelShader(data->frag_shader);
452#elif !defined __CELLOS_LV2__
453    glUseProgram(data->prog_id);
454#else
455    cgGLEnableProfile(cgGLGetLatestProfile(CG_GL_VERTEX));
456    cgGLBindProgram(data->vert_id);
457    cgGLEnableProfile(cgGLGetLatestProfile(CG_GL_FRAGMENT));
458    cgGLBindProgram(data->frag_id);
459#endif
460}
461
462void Shader::Unbind() const
463{
464#if defined USE_D3D9 || defined _XBOX
465    HRESULT hr;
466    hr = g_d3ddevice->SetVertexShader(NULL);
467    hr = g_d3ddevice->SetPixelShader(NULL);
468#elif !defined __CELLOS_LV2__
469    /* FIXME: untested */
470    glUseProgram(0);
471#else
472    /* FIXME: untested */
473    cgGLDisableProfile(cgGLGetLatestProfile(CG_GL_VERTEX));
474    cgGLDisableProfile(cgGLGetLatestProfile(CG_GL_FRAGMENT));
475#endif
476}
477
478Shader::~Shader()
479{
480#if defined USE_D3D9 || defined _XBOX
481    data->vert_shader->Release();
482    data->vert_table->Release();
483    data->frag_shader->Release();
484    data->frag_table->Release();
485#elif !defined __CELLOS_LV2__
486    glDetachShader(data->prog_id, data->vert_id);
487    glDetachShader(data->prog_id, data->frag_id);
488    glDeleteShader(data->vert_id);
489    glDeleteShader(data->frag_id);
490    glDeleteProgram(data->prog_id);
491#else
492    cgDestroyProgram(data->vert_id);
493    cgDestroyProgram(data->frag_id);
494#endif
495    delete data;
496}
497
498/* Try to detect shader compiler features */
499int ShaderData::GetVersion()
500{
501    static int version = 0;
502
503#if !defined USE_D3D9 && !defined _XBOX && !defined __CELLOS_LV2__
504    if (!version)
505    {
506        char buf[4096];
507        GLsizei len;
508
509        int id = glCreateShader(GL_VERTEX_SHADER);
510
511        /* Can we compile 1.30 shaders? */
512        char const *test130 =
513            "#version 130\n"
514            "void main() { gl_Position = vec4(0.0, 0.0, 0.0, 0.0); }";
515        glShaderSource(id, 1, &test130, NULL);
516        glCompileShader(id);
517        glGetShaderInfoLog(id, sizeof(buf), &len, buf);
518        if (len <= 0)
519            version = 130;
520
521        /* If not, can we compile 1.20 shaders? */
522        if (!version)
523        {
524            char const *test120 =
525                "#version 120\n"
526                "void main() { gl_Position = vec4(0.0, 0.0, 0.0, 0.0); }";
527            glShaderSource(id, 1, &test120, NULL);
528            glCompileShader(id);
529            glGetShaderInfoLog(id, sizeof(buf), &len, buf);
530            if (len <= 0)
531                version = 120;
532        }
533
534        /* Otherwise, assume we can compile 1.10 shaders. */
535        if (!version)
536            version = 110;
537
538        glDeleteShader(id);
539    }
540#endif
541
542    return version;
543}
544
545/* Simple shader source patching for old GLSL versions.
546 * If supported version is 1.30, do nothing.
547 * If supported version is 1.20:
548 *  - replace "#version 130" with "#version 120"
549 */
550void ShaderData::Patch(char *dst, char const *vert, char const *frag)
551{
552    int ver_driver = GetVersion();
553
554    strcpy(dst, vert ? vert : frag);
555    if (ver_driver >= 130)
556        return;
557
558    int ver_shader = 110;
559    char *parser = strstr(dst, "#version");
560    if (parser)
561        ver_shader = atoi(parser + strlen("#version"));
562
563    if (ver_shader > 120 && ver_driver <= 120)
564    {
565        char const *end = dst + strlen(dst) + 1;
566
567        /* Find main() */
568        parser = strstr(dst, "main");
569        if (!parser) return;
570        parser = strstr(parser, "(");
571        if (!parser) return;
572        parser = strstr(parser, ")");
573        if (!parser) return;
574        parser = strstr(parser, "{");
575        if (!parser) return;
576        char *main = parser + 1;
577
578        /* Perform main() replaces */
579        char const * const main_replaces[] =
580        {
581#if 0
582            "in vec2 in_Vertex;", "vec2 in_Vertex = gl_Vertex.xy;",
583            "in vec3 in_Vertex;", "vec3 in_Vertex = gl_Vertex.xyz;",
584            "in vec4 in_Vertex;", "vec4 in_Vertex = gl_Vertex.xyzw;",
585
586            "in vec2 in_Color;", "vec2 in_Color = gl_Color.xy;",
587            "in vec3 in_Color;", "vec3 in_Color = gl_Color.xyz;",
588            "in vec4 in_Color;", "vec4 in_Color = gl_Color.xyzw;",
589
590            "in vec2 in_MultiTexCoord0;",
591               "vec2 in_MultiTexCoord0 = gl_MultiTexCoord0.xy;",
592            "in vec2 in_MultiTexCoord1;",
593               "vec2 in_MultiTexCoord1 = gl_MultiTexCoord1.xy;",
594            "in vec2 in_MultiTexCoord2;",
595               "vec2 in_MultiTexCoord2 = gl_MultiTexCoord2.xy;",
596            "in vec2 in_MultiTexCoord3;",
597               "vec2 in_MultiTexCoord3 = gl_MultiTexCoord3.xy;",
598            "in vec2 in_MultiTexCoord4;",
599               "vec2 in_MultiTexCoord4 = gl_MultiTexCoord4.xy;",
600            "in vec2 in_MultiTexCoord5;",
601               "vec2 in_MultiTexCoord5 = gl_MultiTexCoord5.xy;",
602            "in vec2 in_MultiTexCoord6;",
603               "vec2 in_MultiTexCoord6 = gl_MultiTexCoord6.xy;",
604            "in vec2 in_MultiTexCoord7;",
605               "vec2 in_MultiTexCoord7 = gl_MultiTexCoord7.xy;",
606#endif
607
608            NULL
609        };
610
611        for (char const * const *rep = main_replaces; rep[0]; rep += 2)
612        {
613            char *match = strstr(dst, rep[0]);
614            if (match && match < main)
615            {
616                size_t l0 = strlen(rep[0]);
617                size_t l1 = strlen(rep[1]);
618                memmove(main + l1, main, end - main);
619                memcpy(main, rep[1], l1);
620                memset(match, ' ', l0);
621                main += l1;
622                end += l1;
623            }
624        }
625
626        /* Perform small replaces */
627        char const * const fast_replaces[] =
628        {
629            "#version 130", "#version 120",
630            "in vec2", vert ? "attribute vec2" : "varying vec2",
631            "in vec3", vert ? "attribute vec3" : "varying vec3",
632            "in vec4", vert ? "attribute vec4" : "varying vec4",
633            "in mat4", vert ? "attribute mat4" : "varying mat4",
634            "out vec2", "varying vec2",
635            "out vec3", "varying vec3",
636            "out vec4", "varying vec4",
637            "out mat4", "varying mat4",
638            NULL
639        };
640
641        for (char const * const *rep = fast_replaces; rep[0]; rep += 2)
642        {
643            char *match;
644            while ((match = strstr(dst, rep[0])))
645            {
646                size_t l0 = strlen(rep[0]);
647                size_t l1 = strlen(rep[1]);
648
649                if (l1 > l0)
650                    memmove(match + l1, match + l0, (end - match) - l0);
651                memcpy(match, rep[1], l1);
652                if (l1 < l0)
653                    memset(match + l0, ' ', l1 - l0);
654                end += l1 - l0;
655            }
656        }
657    }
658}
659
660} /* namespace lol */
661
Note: See TracBrowser for help on using the repository browser.