changeset 0:b78e329514b8

Add utils proj.
author Oleksander Gavenko <gavenko_a@3g.ua>
date Thu, 17 Jan 2008 21:44:13 +0200
parents
children eff41c7d32bb
files html2dir.sh line-count.sh printargs/Makefile printargs/printargs.c trac-digest.sh
diffstat 5 files changed, 151 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/html2dir.sh	Thu Jan 17 21:44:13 2008 +0200
@@ -0,0 +1,9 @@
+#! /bin/sh
+
+for page in `find -maxdepth 1 -name '*.htm*'`; do
+    dir=`echo $page | sed 's/\.[^.]*$//g'`
+
+    mkdir $dir
+    mv $page $dir
+    mv ${dir}_files ${dir}
+done
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/line-count.sh	Thu Jan 17 21:44:13 2008 +0200
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+count=0
+
+# for file in `find . -maxdepth 1 -regex '.*\.\(c\|h\|cs\|java\)'`; do
+for file in `find . -regex '.*\.\(c\|h\|cs\|java\)'`; do
+    echo $file
+    line_n=`wc -l $file | sed 's/\([0-9]*\) .*/\1/'`
+    count=`expr $count + $line_n`
+done
+
+echo Line count in all source file: $count
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/printargs/Makefile	Thu Jan 17 21:44:13 2008 +0200
@@ -0,0 +1,9 @@
+.PHONY: all
+
+all: printargs.exe
+
+printargs.exe: printargs.c
+	gcc -o $@ $<
+
+clean:
+	rm -f printargs.exe
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/printargs/printargs.c	Thu Jan 17 21:44:13 2008 +0200
@@ -0,0 +1,52 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+void print_help()
+{
+    fprintf(stderr, "Usage:\n");
+    fprintf(stderr, "  printargs [OPTION] arg1 ... argn\n");
+    fprintf(stderr, "    -o file   output to file with quoting args\n");
+    fprintf(stderr, "    -a file   append to file\n");
+    fprintf(stderr, "    -h print  this message\n");
+}
+
+int main(int argc, char **argv)
+{
+    int i;
+
+    if (argc == 1)
+        return EXIT_SUCCESS;
+
+    if (!strcmp("-h", argv[1])) {
+        print_help();
+    } else if (!strcmp("-o", argv[1])) {
+        if (argc < 3)
+            return EXIT_FAILURE;
+        FILE *file = fopen(argv[2], "w");
+        if (file == NULL)
+            return EXIT_FAILURE;
+        for (i = 3; i < argc; i++)
+            if (fprintf(file, "\"%s\"\n", argv[i]) == EOF) {
+                fclose(file);
+                return EXIT_FAILURE;
+            }
+        fclose(file);
+    } else if (!strcmp("-a", argv[1])) {
+        if (argc < 3)
+            return EXIT_FAILURE;
+        FILE *file = fopen(argv[2], "a+");
+        if (file == NULL)
+            return EXIT_FAILURE;
+        for (i = 3; i < argc; i++)
+            if (fprintf(file, "%s\n", argv[i]) == EOF) {
+                fclose(file);
+                return EXIT_FAILURE;
+            }
+        fclose(file);
+    } else
+        for (i = 0; i < argc; i++)
+            printf("\"%s\"\n", argv[i]);
+
+    return EXIT_SUCCESS;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/trac-digest.sh	Thu Jan 17 21:44:13 2008 +0200
@@ -0,0 +1,69 @@
+#!/bin/sh
+# -*- mode: utf8-unix -*-
+
+# In Public Domain.
+# mail:gavenko_a@3g.ua
+
+user=
+pass=
+status=
+
+while [ "$1" ]; do
+    case "$1" in
+        -h|-help|--help)
+            echo "Usage:"
+            echo " > $0 [--help] -u <user> -p <pass>"
+            echo "or with long options:"
+            echo " > $0 [--help] --user=<user> --password=<pass>"
+            exit 0
+            ;;
+        -u)
+            shift
+            if [ "$1" == "" ]; then
+                echo "Could not found username."
+                exit 1
+            else
+                user="$1"
+                status=o${status}
+            fi
+            ;;
+        "--user="*)
+            user=${1#--user=}
+            status=o${status}
+            ;;
+        -p)
+            shift
+            if [ "$1" == "" ]; then
+                echo "Could not found password."
+                exit 1
+            else
+                pass="$1"
+                status=${status}k
+            fi
+            ;;
+        "--password="*)
+            pass=${1#--password=}
+            status=${status}k
+            ;;
+        *)
+            echo "$1 unsuported options."
+            exit 1
+            ;;
+    esac
+
+    shift
+done
+
+if [ "$status" == "ok" ]; then
+    md=`echo -e "${user}:trac:${pass}\c" | md5sum --binary -`
+    md=${md% *-}
+
+    echo "${user}:trac:${md}"
+    exit 0
+else
+    echo "You give duplicate options. Try"
+    echo " > $0 --help"
+    exit 1
+fi
+
+