<?php
$int_numero_depart = $int_numero = 1;
$str_texte = '';
$str_code  = '';
if (isset($_REQUEST['texte']) && is_string($_REQUEST['texte']) && strlen($_REQUEST['texte'])
    && isset($_REQUEST['numero']) && is_string($_REQUEST['numero']) && strlen($_REQUEST['numero'])
    && isset($_REQUEST['bouton']) && is_string($_REQUEST['bouton']))
{
    $int_numero_depart = $int_numero = intval($_REQUEST['numero']);
    $str_texte = $_REQUEST['texte'];
    if (get_magic_quotes_gpc())
    {
        $str_texte = stripslashes($str_texte);
    }
    $arr_str_code = array();
    $arr_str_texte = explode("\n", $str_texte);
    foreach ($arr_str_texte as $str_ligne)
    {
        $str_ligne = trim($str_ligne);
        if (strlen($str_ligne) > 0)
        {
            $str_ligne = preg_replace('/\b(\d+)\b/', $int_numero, $str_ligne, -1, $int_count);
            if ($int_count > 0)
            {
                $arr_str_code[] = $str_ligne;
                $int_numero++;
            }
        }
    }
    $str_code = implode("\r\n", $arr_str_code);
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
        <title>Renuméroter les #define d'un fichier de ressource.h</title>
        <style type="text/css">
        <!--
        body *
        {
            font-family: monospace;
            font-size: 8pt;
        }
        textarea
        {
            width: 600px;
        }
        form
        {
            margin: 0;
        }
        div
        {
            margin: 0 0 5px 0;
        }
        -->
        </style>
        <script type="text/javascript">
        <!--;
            function on_load()
            {
                if (document && document.getElementById)
                {
                    var obj_input = document.getElementById('texte');
                    if (obj_input && obj_input.focus)
                    {
                        obj_input.focus();
                    }
                }
            }
        //-->
        </script>
    </head>
    <body onload="on_load();">
        <form method="post" action="">
            <div>
                <label for="numero">Numéro:</label> <input id="numero" name="numero" value="<?php echo htmlspecialchars($int_numero_depart, ENT_QUOTES); ?>" />
            </div>
            <div>
                <textarea id="texte" name="texte" rows="20" cols="80"><?php echo htmlspecialchars($str_texte, ENT_QUOTES); ?></textarea>
            </div>
            <div>
                <input type="submit" class="submit" name="bouton" value="Renuméroter" />
            </div>
        </form>
<?php
if ($str_code)
{
    $int_ligne = substr_count($str_code, "\n") + 1;
    echo '<div><textarea rows="',$int_ligne,'" cols="80" onclick="this.select();">',htmlspecialchars($str_code, ENT_QUOTES),'</textarea></div>';
}
echo '<hr />';
highlight_file(__FILE__);
?>
    </body>
</html>