Пример #1
0
    }
}
function confirm_notice($snt)
{
    $msg = gen_total_msg($snt);
    echo_msg($msg);
    $confirm = ask_y_or_n("Are you sure to send the above message?");
    if ($confirm) {
        echo "Comment mail will be sent.\n\n";
        send($msg);
    } else {
        echo "Comment mail is cancelled.\n\n";
    }
}
function manual()
{
    echo "Welcome to S&T comment system.\n\n";
    $snt = select_snt();
    confirm_notice($snt);
    echo "Bye.\n";
}
if ($argc === 1) {
    manual();
} else {
    if ($argv[1] === "auto") {
        auto();
    } else {
        my_log(__FILE__, "Command arguments are invalid\n");
        exit(1);
    }
}
Пример #2
0
function genDoc($fname, $imports = array())
{
    $doc = '';
    $lines = file($fname);
    $cLines = count($lines);
    $classOpened = false;
    for ($i = 0; $i < $cLines; $i++) {
        $comment = '';
        $ln = $lines[$i];
        if (!trim($ln)) {
            continue;
        }
        #found import
        if (preg_match('/import/', $ln)) {
            $classpath = trim(preg_replace('/(import)|\\s+|;/', '', $ln));
            $parts = explode('.', $classpath);
            $shortcut = $parts[count($parts) - 1];
            $imports[$shortcut] = $classpath;
        }
        #comment
        if (preg_match('/^\\s*\\/\\*/', $ln)) {
            $comment .= $ln;
            if (!preg_match('/\\*\\//', $ln)) {
                $skip = false;
                $cnt = 1;
                while ($cnt > 0) {
                    $i++;
                    $ln = $lines[$i];
                    if (preg_match('/\\@private/', $ln)) {
                        $skip = true;
                    }
                    $comment .= $ln;
                    if (preg_match('/\\*\\//', $ln)) {
                        $cnt--;
                    }
                    if (preg_match('/^\\s*\\/\\*/', $ln)) {
                        $cnt++;
                    }
                }
                if ($skip) {
                    $comment = '';
                }
            }
        } elseif (preg_match('/^\\s*\\/\\//', $ln)) {
            $comment .= $ln;
        }
        #skip empty lines
        while ($i + 1 < $cLines && !trim($lines[$i + 1])) {
            $i++;
        }
        #found comment. Search for definitions{
        #manual section
        if (preg_match('/@manual/', $comment)) {
            $doc .= "<div class=\"manual\">" . manual($comment) . "</div>\n";
            #vars & functions
        } elseif ($comment && $i + 1 < $cLines && preg_match('/public/', $lines[$i + 1])) {
            $definition = preg_replace('/\\{|;/', '', $lines[$i + 1]);
            $doc .= definition($definition, $imports) . comment($comment, $imports);
            #classes
        } elseif ($comment && $i + 1 < $cLines && preg_match('/class|interface/', $lines[$i + 1]) && !preg_match('/\\}/', $lines[$i + 1])) {
            if ($classOpened) {
                $doc .= "</div>\n";
            }
            $definition = preg_replace('/\\{|;/', '', $lines[$i + 1]);
            $doc .= "<dic class=\"classContainer\">" . classDef($definition, $imports) . comment($comment, $imports);
            $classOpened = true;
            #typedefs
        } elseif ($comment && $i + 1 < $cLines && preg_match('/typedef/', $lines[$i + 1])) {
            $definition = preg_replace('/\\{|;/', ' ', $lines[$i + 1]);
            $doc .= "<div class=\"classContainer\">" . comment($comment, $imports) . classDef($definition, $imports);
            $body = '';
            $i++;
            $ln = $lines[$i];
            $m = array();
            $opened = preg_match_all('/\\{/', $ln, $m) - preg_match_all('/\\}/', $ln, $m);
            while ($opened > 0) {
                $i++;
                $ln = $lines[$i];
                $opened += preg_match_all('/\\{/', $ln, $m) - preg_match_all('/\\}/', $ln, $m);
                $body .= $ln;
            }
            if ($body) {
                $doc .= "<div class=\"typedefBody\">{\n" . definition($body, $imports) . "</div>\n";
            }
            $doc .= "</div>\n";
        }
        #}
    }
    //for(lines)
    if ($classOpened) {
        $doc .= "</div>\n";
    }
    return $doc;
}