diff --git a/awkfun/BBS-list b/awkfun/BBS-list deleted file mode 100644 index 1007417..0000000 --- a/awkfun/BBS-list +++ /dev/null @@ -1,11 +0,0 @@ -aardvark 555-5553 1200/300 B -alpo-net 555-3412 2400/1200/300 A -barfly 555-7685 1200/300 A -bites 555-1675 2400/1200/300 A -camelot 555-0542 300 C -core 555-2912 1200/300 C -fooey 555-1234 2400/1200/300 B -foot 555-6699 1200/300 B -macfoo 555-6480 1200/300 A -sdace 555-3430 2400/1200/300 A -sabafoo 555-2127 1200/300 C diff --git a/awkfun/advice b/awkfun/advice deleted file mode 100755 index bb2ae8e..0000000 --- a/awkfun/advice +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/awk -f - -BEGIN { - print "Don't Panic!" -} diff --git a/awkfun/ex_1.4a b/awkfun/ex_1.4a deleted file mode 100755 index f02f043..0000000 --- a/awkfun/ex_1.4a +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -awk '/12/ { print $0 } - /21/ { print $0 }' BBS-list inventory-shipped diff --git a/awkfun/inventory-shipped b/awkfun/inventory-shipped deleted file mode 100644 index 6788a0e..0000000 --- a/awkfun/inventory-shipped +++ /dev/null @@ -1,17 +0,0 @@ -Jan 13 25 15 115 -Feb 15 32 24 226 -Mar 15 24 34 228 -Apr 31 52 63 420 -May 16 34 29 208 -Jun 31 42 75 492 -Jul 24 34 67 436 -Aug 15 34 47 316 -Sep 13 55 37 277 -Oct 29 54 68 525 -Nov 20 87 82 577 -Dec 17 35 61 401 - -Jan 21 36 64 620 -Feb 26 58 80 652 -Mar 24 75 70 495 -Apr 21 70 74 514 diff --git a/cpp-practice/.gitignore b/cpp-practice/.gitignore deleted file mode 100644 index bf25c60..0000000 --- a/cpp-practice/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*/bin/* diff --git a/cpp-practice/Makefile b/cpp-practice/Makefile deleted file mode 100644 index bedc98e..0000000 --- a/cpp-practice/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -all: - cd ./basics && $(MAKE) - cd ./opengl && $(MAKE) - - -.PHONY: all diff --git a/cpp-practice/README b/cpp-practice/README deleted file mode 100644 index e8b6086..0000000 --- a/cpp-practice/README +++ /dev/null @@ -1 +0,0 @@ -This is where I practice C++ stuff. diff --git a/cpp-practice/basics/Makefile b/cpp-practice/basics/Makefile deleted file mode 100644 index 26792f4..0000000 --- a/cpp-practice/basics/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -CPPC := g++ - -ALL_TARGETS = bin/hello-world - - -bin/%: src/%.cpp - $(CPPC) $^ -o $@ - - -all: $(ALL_TARGETS) - -clean: - rm -vf ./bin/* - -test: - ./tests/test_hello_world - - -.PHONY: all clean test diff --git a/cpp-practice/basics/bin/.keep b/cpp-practice/basics/bin/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/cpp-practice/basics/docs/tutorial.pdf b/cpp-practice/basics/docs/tutorial.pdf deleted file mode 100644 index b1b463f..0000000 Binary files a/cpp-practice/basics/docs/tutorial.pdf and /dev/null differ diff --git a/cpp-practice/basics/src/hello-world.cpp b/cpp-practice/basics/src/hello-world.cpp deleted file mode 100644 index 29feca2..0000000 --- a/cpp-practice/basics/src/hello-world.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include -using namespace std; - -int main() -{ - cout << "Hello World!" << endl; - return 0; -} diff --git a/cpp-practice/basics/tests/test_hello_world b/cpp-practice/basics/tests/test_hello_world deleted file mode 100755 index c3d3d0e..0000000 --- a/cpp-practice/basics/tests/test_hello_world +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -./bin/hello-world > /dev/null 2>&1 - -exit $? diff --git a/curses-practice/.gitignore b/curses-practice/.gitignore deleted file mode 100644 index 2dc1559..0000000 --- a/curses-practice/.gitignore +++ /dev/null @@ -1 +0,0 @@ -demo/exe/* diff --git a/curses-practice/COPYING b/curses-practice/COPYING deleted file mode 100644 index 3e34ea6..0000000 --- a/curses-practice/COPYING +++ /dev/null @@ -1,23 +0,0 @@ -Copyright (c) 2001, Pradeep Padala (ppadala@gmail.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, distribute with -modifications, sublicense, and/or sell copies of the Software, and to permit -persons to whom the Software is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name(s) of the above copyright holders -shall not be used in advertising or otherwise to promote the sale, use or -other dealings in this Software without prior written authorization. diff --git a/curses-practice/JustForFun/Makefile b/curses-practice/JustForFun/Makefile deleted file mode 100644 index 3f0890e..0000000 --- a/curses-practice/JustForFun/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -# Makefile for JustForFun Files - -# A few variables - -CC=gcc -LIBS=-lncurses - -SRC_DIR=. -EXE_DIR=../demo/exe - -EXES = \ - ${EXE_DIR}/hanoi \ - ${EXE_DIR}/life\ - ${EXE_DIR}/magic \ - ${EXE_DIR}/queens \ - ${EXE_DIR}/shuffle \ - ${EXE_DIR}/tt - -${EXE_DIR}/%: %.o - ${CC} -o $@ $< ${LIBS} - -%.o: ${SRC_DIR}/%.c - ${CC} -o $@ -c $< - -all: ${EXES} - -clean: - @rm -f ${EXES} diff --git a/curses-practice/JustForFun/README b/curses-practice/JustForFun/README deleted file mode 100644 index a5d743f..0000000 --- a/curses-practice/JustForFun/README +++ /dev/null @@ -1,10 +0,0 @@ -Description of files --------------------- -JustForFun - | - |----> hanoi.c -- The Towers of Hanoi Solver - |----> life.c -- The Game of Life demo - |----> magic.c -- An Odd Order Magic Square builder - |----> queens.c -- The famous N-Queens Solver - |----> shuffle.c -- A fun game, if you have time to kill - |----> tt.c -- A very trivial typing tutor diff --git a/curses-practice/JustForFun/hanoi.c b/curses-practice/JustForFun/hanoi.c deleted file mode 100644 index 4085a93..0000000 --- a/curses-practice/JustForFun/hanoi.c +++ /dev/null @@ -1,178 +0,0 @@ -#include - -#define POSX 10 -#define POSY 5 -#define DISC_CHAR '*' -#define PEG_CHAR '#' -#define TIME_OUT 300 - -typedef struct _peg_struct { - int n_discs; /* Number of discs at present */ - int bottomx, bottomy; /* bottom x, bottom y co-ord */ - int *sizes; /* The disc sizes array */ -}peg; - -void init_pegs(peg *p_my_pegs, int n_discs); -void show_pegs(WINDOW *win, peg *p_my_pegs, int n_discs); -void free_pegs(peg *p_my_pegs, int n_discs); -void solve_hanoi(peg *p_my_pegs, int n, int src, int aux, int dst); -void move_disc(peg *p_my_pegs, int n_discs, int src, int dst); -void print_in_middle(int startx, int starty, int width, char *string, WINDOW *win); -void check_usr_response(peg *p_my_pegs, int n_discs); - -int store_n_discs; -char *welcome_string = "Enter the number of discs you want to be solved: "; - -int main(int argc, char *argv[]) -{ int n_discs; - peg my_pegs[3]; - - initscr(); /* Start curses mode */ - cbreak(); /* Line buffering disabled. Pass on every thing */ - keypad(stdscr, TRUE); - curs_set(FALSE); - - print_in_middle(0, LINES / 2, COLS, welcome_string, NULL); - scanw("%d", &n_discs); - - timeout(TIME_OUT); - noecho(); - store_n_discs = n_discs; - - init_pegs(my_pegs, n_discs); - show_pegs(stdscr, my_pegs, n_discs); - solve_hanoi(my_pegs, n_discs, 0, 1, 2); - - free_pegs(my_pegs, n_discs); - endwin(); /* End curses mode */ - return 0; -} - -void solve_hanoi(peg *p_my_pegs, int n_discs, int src, int aux, int dst) -{ if(n_discs == 0) - return; - solve_hanoi(p_my_pegs, n_discs - 1, src, dst, aux); - move_disc(p_my_pegs, store_n_discs, src, dst); - show_pegs(stdscr, p_my_pegs, store_n_discs); - check_usr_response(p_my_pegs, store_n_discs); - solve_hanoi(p_my_pegs, n_discs - 1, aux, src, dst); -} - -void check_usr_response(peg *p_my_pegs, int n_discs) -{ int ch; - - ch = getch(); /* Waits for TIME_OUT milliseconds */ - if(ch == ERR) - return; - else - if(ch == KEY_F(1)) - { free_pegs(p_my_pegs, n_discs); - endwin(); - exit(0); - } -} - -void move_disc(peg *p_my_pegs, int n_discs, int src, int dst) -{ int temp, index; - - --p_my_pegs[src].n_discs; - index = 0; - while(p_my_pegs[src].sizes[index] == 0 && index != n_discs) - ++index; - temp = p_my_pegs[src].sizes[index]; - p_my_pegs[src].sizes[index] = 0; - - index = 0; - while(p_my_pegs[dst].sizes[index] == 0 && index != n_discs) - ++index; - --index; - p_my_pegs[dst].sizes[index] = temp; - ++p_my_pegs[dst].n_discs; -} - -void init_pegs(peg *p_my_pegs, int n_discs) -{ int size, temp, i; - - p_my_pegs[0].n_discs = n_discs; - - /* Allocate memory for size array - * atmost the number of discs on a peg can be n_discs - */ - for(i = 0; i < n_discs; ++i) - p_my_pegs[i].sizes = (int *)calloc(n_discs, sizeof(int)); - size = 3; - for(i = 0;i < n_discs; ++i, size += 2) - p_my_pegs[0].sizes[i] = size; - - temp = (p_my_pegs[0].sizes[n_discs - 1] / 2); - p_my_pegs[0].bottomx = POSX + 1 + temp; - p_my_pegs[0].bottomy = POSY + 2 + n_discs; - - p_my_pegs[1].bottomx = p_my_pegs[0].bottomx + 2 + 2 * temp; - p_my_pegs[1].bottomy = POSY + 2 + n_discs; - - p_my_pegs[2].bottomx = p_my_pegs[1].bottomx + 2 + 2 * temp; - p_my_pegs[2].bottomy = POSY + 2 + n_discs; -} - -void show_pegs(WINDOW *win, peg *p_my_pegs, int n_discs) -{ int i, j, k, x, y, size; - - wclear(win); - attron(A_REVERSE); - mvprintw(24, 0, "Press F1 to Exit"); - attroff(A_REVERSE); - for(i = 0;i < 3; ++i) - mvwprintw( win, p_my_pegs[i].bottomy - n_discs - 1, - p_my_pegs[i].bottomx, "%c", PEG_CHAR); - y = p_my_pegs[0].bottomy - n_discs; - for(i = 0; i < 3; ++i) /* For each peg */ - { for(j = 0; j < n_discs; ++ j) /* For each row */ - { if(p_my_pegs[i].sizes[j] != 0) - { size = p_my_pegs[i].sizes[j]; - x = p_my_pegs[i].bottomx - (size / 2); - for(k = 0; k < size; ++k) - mvwprintw(win, y, x + k, "%c", DISC_CHAR); - } - else - mvwprintw(win, y, p_my_pegs[i].bottomx, "%c", PEG_CHAR); - ++y; - } - y = p_my_pegs[0].bottomy - n_discs; - } - wrefresh(win); -} - -void free_pegs(peg *p_my_pegs, int n_discs) -{ int i; - - for(i = 0;i < n_discs; ++i) - free(p_my_pegs[i].sizes); -} - -/* -------------------------------------------------------------* - * startx = 0 means at present x * - * starty = 0 means at present y * - * win = NULL means take stdscr * - * -------------------------------------------------------------*/ - -void print_in_middle(int startx, int starty, int width, char *string, WINDOW *win) -{ int length, x, y; - float temp; - - if(win == NULL) - win = stdscr; - getyx(win, y, x); - if(startx != 0) - x = startx; - if(starty != 0) - y = starty; - if(width == 0) - width = 80; - - length = strlen(string); - temp = (width - length)/ 2; - x = startx + (int)temp; - mvwprintw(win, y, x, "%s", string); - refresh(); -} diff --git a/curses-practice/JustForFun/life.c b/curses-practice/JustForFun/life.c deleted file mode 100644 index 99da8a3..0000000 --- a/curses-practice/JustForFun/life.c +++ /dev/null @@ -1,107 +0,0 @@ -#include - -int STARTX = 0; -int STARTY = 0; -int ENDX = 79; -int ENDY = 24; - -#define CELL_CHAR '#' -#define TIME_OUT 300 - -typedef struct _state { - int oldstate; - int newstate; -}state; - -void display(WINDOW *win, state **area, int startx, int starty, int endx, int endy); -void calc(state **area, int x, int y); -void update_state(state **area, int startx, int starty, int endx, int endy); - -int main() -{ state **workarea; - int i, j; - - initscr(); - cbreak(); - timeout(TIME_OUT); - keypad(stdscr, TRUE); - - ENDX = COLS - 1; - ENDY = LINES - 1; - - workarea = (state **)calloc(COLS, sizeof(state *)); - for(i = 0;i < COLS; ++i) - workarea[i] = (state *)calloc(LINES, sizeof(state)); - - /* For inverted U */ - workarea[39][15].newstate = TRUE; - workarea[40][15].newstate = TRUE; - workarea[41][15].newstate = TRUE; - workarea[39][16].newstate = TRUE; - workarea[39][17].newstate = TRUE; - workarea[41][16].newstate = TRUE; - workarea[41][17].newstate = TRUE; - update_state(workarea, STARTX, STARTY, ENDX, ENDY); - - /* For block */ -/* - workarea[37][13].newstate = TRUE; - workarea[37][14].newstate = TRUE; - workarea[38][13].newstate = TRUE; - workarea[38][14].newstate = TRUE; - - update_state(workarea, STARTX, STARTY, ENDX, ENDY); -*/ - display(stdscr, workarea, STARTX, STARTY, ENDX, ENDY); - while(getch() != KEY_F(1)) - { for(i = STARTX; i <= ENDX; ++i) - for(j = STARTY; j <= ENDY; ++j) - calc(workarea, i, j); - update_state(workarea, STARTX, STARTY, ENDX, ENDY); - display(stdscr, workarea, STARTX, STARTY, ENDX, ENDY); - } - - endwin(); - return 0; -} - -void display(WINDOW *win, state **area, int startx, int starty, int endx, int endy) -{ int i, j; - wclear(win); - for(i = startx; i <= endx; ++i) - for(j = starty;j <= endy; ++j) - if(area[i][j].newstate == TRUE) - mvwaddch(win, j, i, CELL_CHAR); - wrefresh(win); -} - -void calc(state **area, int i, int j) -{ int neighbours; - int newstate; - - neighbours = - area[(i - 1 + COLS) % COLS][j].oldstate + - area[(i - 1 + COLS) % COLS][(j - 1 + LINES) % LINES].oldstate + - area[(i - 1 + COLS) % COLS][(j + 1) % LINES].oldstate + - area[(i + 1) % COLS][j].oldstate + - area[(i + 1) % COLS][(j - 1 + LINES) % LINES].oldstate + - area[(i + 1) % COLS][(j + 1) % LINES].oldstate + - area[i][(j - 1 + LINES) % LINES].oldstate + - area[i][(j + 1) % LINES].oldstate; - - newstate = FALSE; - if(area[i][j].oldstate == TRUE && (neighbours == 2 || neighbours == 3)) - newstate = TRUE; - else - if(area[i][j].oldstate == FALSE && neighbours == 3) - newstate = TRUE; - area[i][j].newstate = newstate; -} - -void update_state(state **area, int startx, int starty, int endx, int endy) -{ int i, j; - - for(i = startx; i <= endx; ++i) - for(j = starty; j <= endy; ++j) - area[i][j].oldstate = area[i][j].newstate; -} diff --git a/curses-practice/JustForFun/magic.c b/curses-practice/JustForFun/magic.c deleted file mode 100644 index c93b5d8..0000000 --- a/curses-practice/JustForFun/magic.c +++ /dev/null @@ -1,161 +0,0 @@ -#include -#include - -#define STARTX 9 -#define STARTY 3 -#define WIDTH 6 -#define HEIGHT 4 - -#define TRACE_VALUE TRACE_MAXIMUM - -void board( WINDOW *win, int starty, int startx, int lines, int cols, - int tile_width, int tile_height); -void magic(int **, int); -void print(int **, int); -void magic_board(int **a,int n); - -int main(int argc, char *argv[]) -{ - - int **a,n,i; - - if(argc != 2) - { printf("Usage: %s \n", argv[0]); - exit(0); - } - n = atoi(argv[1]); - if(n % 2 == 0) - { printf("Sorry !!! I don't know how to create magic square of even order\n"); - printf("The order should be an odd number\n"); - exit(0); - } - a = (int **) malloc(n * sizeof(int*)); - for(i = 0;i < n;++i) - a[i] = (int *)malloc(n * sizeof(int)); - - magic(a,n); - - initscr(); - curs_set(0); - noecho(); - magic_board(a,n); - getch(); - endwin(); - - return; -} - -void magic(int **a, int n) -{ - int i,j,k; - int row,col; - for(i = 0;i < n;++i) - for(j = 0;j < n;++j) - a[i][j] = -1; - row = 0; - col = n / 2; - - k = 1; - a[row][col] = k; - - while(k != n * n) - { - if(row == 0 && col != n - 1) - { row = n - 1; - col ++; - a[row][col] = ++k; - } - else if(row != 0 && col != n - 1) - { if(a[row - 1][col + 1] == -1) - { row --; - col ++; - a[row][col] = ++k; - } - else - { - row ++; - a[row][col] = ++k; - } - } - else if(row != 0 && col == n - 1) - { - row --; - col = 0; - a[row][col] = ++k; - } - else if(row == 0 && col == n - 1) - { row ++; - a[row][col] = ++k; - } - - } - return; -} - -void print(int **a,int n) -{ int i,j; - int x,y; - x = STARTX; - y = STARTY; - mvprintw(1,30,"MAGIC SQUARE"); - for(i = 0;i < n;++i) - { for(j = 0;j < n;++j) - { mvprintw(y,x,"%d",a[i][j]); - if(n > 9) - x += 4; - else - x += 6; - } - x = STARTX; - if(n > 7) - y += 2; - else - y += 3; - } - refresh(); -} -void board(WINDOW *win, int starty, int startx, int lines, int cols, - int tile_width, int tile_height) -{ int endy, endx, i, j; - - endy = starty + lines * tile_height; - endx = startx + cols * tile_width; - - for(j = starty; j <= endy; j += tile_height) - for(i = startx; i <= endx; ++i) - mvwaddch(win, j, i, ACS_HLINE); - for(i = startx; i <= endx; i += tile_width) - for(j = starty; j <= endy; ++j) - mvwaddch(win, j, i, ACS_VLINE); - mvwaddch(win, starty, startx, ACS_ULCORNER); - mvwaddch(win, endy, startx, ACS_LLCORNER); - mvwaddch(win, starty, endx, ACS_URCORNER); - mvwaddch(win, endy, endx, ACS_LRCORNER); - for(j = starty + tile_height; j <= endy - tile_height; j += tile_height) - { mvwaddch(win, j, startx, ACS_LTEE); - mvwaddch(win, j, endx, ACS_RTEE); - for(i = startx + tile_width; i <= endx - tile_width; i += tile_width) - mvwaddch(win, j, i, ACS_PLUS); - } - for(i = startx + tile_width; i <= endx - tile_width; i += tile_width) - { mvwaddch(win, starty, i, ACS_TTEE); - mvwaddch(win, endy, i, ACS_BTEE); - } - wrefresh(win); -} - -void magic_board(int **a,int n) -{ int i,j, deltax, deltay; - int startx, starty; - - starty = (LINES - n * HEIGHT) / 2; - startx = (COLS - n * WIDTH) / 2; - board(stdscr, starty, startx, n, n, WIDTH, HEIGHT); - deltay = HEIGHT / 2; - deltax = WIDTH / 2; - for(i = 0;i < n; ++i) - for(j = 0; j < n; ++j) - mvprintw(starty + j * HEIGHT + deltay, - startx + i * WIDTH + deltax, - "%d", a[i][j]); -} diff --git a/curses-practice/JustForFun/queens.c b/curses-practice/JustForFun/queens.c deleted file mode 100644 index 82b11c1..0000000 --- a/curses-practice/JustForFun/queens.c +++ /dev/null @@ -1,122 +0,0 @@ -#include -#include - -#define QUEEN_CHAR '*' - -int *nqueens(int num); -int place(int current, int *position); -int print(int *positions, int num_queens); -void board(WINDOW *win, int starty, int startx, int lines, int cols, - int tile_width, int tile_height); - -int main(int argc, char *argv[]) -{ - int num_queens, *positions, count; - - if(argc != 2) - { printf("Usage: %s \n", argv[0]); - exit(1); - } - - num_queens = atoi(argv[1]); - initscr(); - cbreak(); - keypad(stdscr, TRUE); - positions = nqueens(num_queens); - free(positions); - endwin(); - return 0; -} - -int *nqueens(int num) -{ - int current, *position, num_solutions = 0; - - position = (int *) calloc(num + 1, sizeof(int)); - - position[1] = 0; - current = 1; /* current queen is being checked */ - /* position[current] is the coloumn*/ - while(current > 0){ - position[current] += 1; - while(position[current] <= num && !place(current, position) ) - position[current] += 1; - if(position[current] <= num){ - if(current == num) { - ++num_solutions; - print(position, num); - } - else { - current += 1; - position[current] = 0; - } - } - else current -= 1; /* backtrack */ - } - printf("Total Number of Solutions : %d\n", num_solutions); - return(position); -} - -int place(int current, int *position) -{ - int i; - if(current == 1) return(1); - for(i = 1; i < current; ++i) - if(position[i] == position[current]) return(0); - else if(abs(position[i] - position[current]) == - abs(i - current)) - return(0); - - return(1); -} - -int print(int *positions, int num_queens) -{ int count; - int y = 2, x = 2, w = 4, h = 2; - static int solution = 1; - - mvprintw(0, 0, "Solution No: %d", solution++); - board(stdscr, y, x, num_queens, num_queens, w, h); - for(count = 1; count <= num_queens; ++count) - { int tempy = y + (count - 1) * h + h / 2; - int tempx = x + (positions[count] - 1) * w + w / 2; - mvaddch(tempy, tempx, QUEEN_CHAR); - } - refresh(); - mvprintw(LINES - 2, 0, "Press Any Key to See next solution (F1 to Exit)"); - if(getch() == KEY_F(1)) - { endwin(); - exit(0); - } - clear(); -} - -void board(WINDOW *win, int starty, int startx, int lines, int cols, - int tile_width, int tile_height) -{ int endy, endx, i, j; - - endy = starty + lines * tile_height; - endx = startx + cols * tile_width; - - for(j = starty; j <= endy; j += tile_height) - for(i = startx; i <= endx; ++i) - mvwaddch(win, j, i, ACS_HLINE); - for(i = startx; i <= endx; i += tile_width) - for(j = starty; j <= endy; ++j) - mvwaddch(win, j, i, ACS_VLINE); - mvwaddch(win, starty, startx, ACS_ULCORNER); - mvwaddch(win, endy, startx, ACS_LLCORNER); - mvwaddch(win, starty, endx, ACS_URCORNER); - mvwaddch(win, endy, endx, ACS_LRCORNER); - for(j = starty + tile_height; j <= endy - tile_height; j += tile_height) - { mvwaddch(win, j, startx, ACS_LTEE); - mvwaddch(win, j, endx, ACS_RTEE); - for(i = startx + tile_width; i <= endx - tile_width; i += tile_width) - mvwaddch(win, j, i, ACS_PLUS); - } - for(i = startx + tile_width; i <= endx - tile_width; i += tile_width) - { mvwaddch(win, starty, i, ACS_TTEE); - mvwaddch(win, endy, i, ACS_BTEE); - } - wrefresh(win); -} diff --git a/curses-practice/JustForFun/shuffle.c b/curses-practice/JustForFun/shuffle.c deleted file mode 100644 index d1431bd..0000000 --- a/curses-practice/JustForFun/shuffle.c +++ /dev/null @@ -1,205 +0,0 @@ -#include - -#define STARTX 9 -#define STARTY 3 -#define WIDTH 6 -#define HEIGHT 4 - -#define BLANK 0 - -typedef struct _tile { - int x; - int y; -}tile; - -void init_board(int **board, int n, tile *blank); -void board(WINDOW *win, int starty, int startx, int lines, int cols, - int tile_width, int tile_height); -void shuffle_board(int **board, int n); -void move_blank(int direction, int **s_board, int n, tile *blank); -int check_win(int **s_board, int n, tile *blank); - -enum { LEFT, RIGHT, UP, DOWN }; - -int main(int argc, char *argv[]) -{ int **s_board; - int n, i, ch; - tile blank; - - if(argc != 2) - { printf("Usage: %s \n", argv[0]); - exit(1); - } - n = atoi(argv[1]); - - s_board = (int **)calloc(n, sizeof(int *)); - for(i = 0;i < n; ++i) - s_board[i] = (int *)calloc(n, sizeof(int)); - init_board(s_board, n, &blank); - initscr(); - keypad(stdscr, TRUE); - cbreak(); - shuffle_board(s_board, n); - while((ch = getch()) != KEY_F(1)) - { switch(ch) - { case KEY_LEFT: - move_blank(RIGHT, s_board, n, &blank); - break; - case KEY_RIGHT: - move_blank(LEFT, s_board, n, &blank); - break; - case KEY_UP: - move_blank(DOWN, s_board, n, &blank); - break; - case KEY_DOWN: - move_blank(UP, s_board, n, &blank); - break; - } - shuffle_board(s_board, n); - if(check_win(s_board, n, &blank) == TRUE) - { mvprintw(24, 0, "You Win !!!\n"); - refresh(); - break; - } - } - endwin(); - return 0; -} - -void move_blank(int direction, int **s_board, int n, tile *blank) -{ int temp; - - switch(direction) - { case LEFT: - { if(blank->x != 0) - { --blank->x; - temp = s_board[blank->x][blank->y]; - s_board[blank->x + 1][blank->y] = temp; - s_board[blank->x][blank->y] = BLANK; - } - } - break; - case RIGHT: - { if(blank->x != n - 1) - { ++blank->x; - temp = s_board[blank->x][blank->y]; - s_board[blank->x - 1][blank->y] = temp; - s_board[blank->x][blank->y] = BLANK; - } - } - break; - case UP: - { if(blank->y != 0) - { --blank->y; - temp = s_board[blank->x][blank->y]; - s_board[blank->x][blank->y + 1] = temp; - s_board[blank->x][blank->y] = BLANK; - } - } - break; - case DOWN: - { if(blank->y != n - 1) - { ++blank->y; - temp = s_board[blank->x][blank->y]; - s_board[blank->x][blank->y - 1] = temp; - s_board[blank->x][blank->y] = BLANK; - } - } - break; - } -} - -int check_win(int **s_board, int n, tile *blank) -{ int i, j; - - s_board[blank->x][blank->y] = n * n; - for(i = 0;i < n; ++i) - for(j = 0;j < n; ++j) - if(s_board[i][j] != j * n + i + 1) - { s_board[blank->x][blank->y] = BLANK; - return FALSE; - } - - s_board[blank->x][blank->y] = BLANK; - return TRUE; -} - -void init_board(int **s_board, int n, tile *blank) -{ int i, j, k; - int *temp_board; - - temp_board = (int *)calloc(n * n, sizeof(int)); - srand(time(NULL)); - for(i = 0;i < n * n; ++i) - { -repeat : - k = rand() % (n * n); - for(j = 0;j <= i - 1; ++j) - if (k == temp_board[j]) - goto repeat; - else - temp_board[i] = k; - } - k = 0; - for (i = 0;i < n;++i) - for(j = 0;j < n; ++j,++k) - { if(temp_board[k] == 0) - { blank->x = i; - blank->y = j; - } - s_board[i][j] = temp_board[k]; - } - free(temp_board); -} - -void board(WINDOW *win, int starty, int startx, int lines, int cols, - int tile_width, int tile_height) -{ int endy, endx, i, j; - - endy = starty + lines * tile_height; - endx = startx + cols * tile_width; - - for(j = starty; j <= endy; j += tile_height) - for(i = startx; i <= endx; ++i) - mvwaddch(win, j, i, ACS_HLINE); - for(i = startx; i <= endx; i += tile_width) - for(j = starty; j <= endy; ++j) - mvwaddch(win, j, i, ACS_VLINE); - mvwaddch(win, starty, startx, ACS_ULCORNER); - mvwaddch(win, endy, startx, ACS_LLCORNER); - mvwaddch(win, starty, endx, ACS_URCORNER); - mvwaddch(win, endy, endx, ACS_LRCORNER); - for(j = starty + tile_height; j <= endy - tile_height; j += tile_height) - { mvwaddch(win, j, startx, ACS_LTEE); - mvwaddch(win, j, endx, ACS_RTEE); - for(i = startx + tile_width; i <= endx - tile_width; i += tile_width) - mvwaddch(win, j, i, ACS_PLUS); - } - for(i = startx + tile_width; i <= endx - tile_width; i += tile_width) - { mvwaddch(win, starty, i, ACS_TTEE); - mvwaddch(win, endy, i, ACS_BTEE); - } - wrefresh(win); -} - -void shuffle_board(int **s_board, int n) -{ int i,j, deltax, deltay; - int startx, starty; - - starty = (LINES - n * HEIGHT) / 2; - startx = (COLS - n * WIDTH) / 2; - clear(); - mvprintw(24, 0, "Press F1 to Exit"); - board(stdscr, starty, startx, n, n, WIDTH, HEIGHT); - deltay = HEIGHT / 2; - deltax = WIDTH / 2; - for(j = 0; j < n; ++j) - for(i = 0;i < n; ++i) - if(s_board[i][j] != BLANK) - mvprintw(starty + j * HEIGHT + deltay, - startx + i * WIDTH + deltax, - "%-2d", s_board[i][j]); - refresh(); -} - - diff --git a/curses-practice/JustForFun/tt.c b/curses-practice/JustForFun/tt.c deleted file mode 100644 index 178eefa..0000000 --- a/curses-practice/JustForFun/tt.c +++ /dev/null @@ -1,223 +0,0 @@ -#include -#include -#include -#include - -#define HSIZE 60 -#define LENGTH 75 -#define WIDTH 10 -#define STARTX 1 -#define STARTY 5 -#define STATUSX 1 -#define STATUSY 25 - -#define KEY_F1 265 - -int print_menu(); -void print_byebye(); -void create_test_string(); -void print_time(time_t startt, time_t endt, int mistakes); -void print_in_middle(int startx, int starty, int width, char *string, WINDOW *win); - -char *groups[] = { "`123456" , - "7890-=" , - "~!@#$%^" , - "&*()_+" , - "<>?" , - ",./\\" , - "asdfg", - "jkl;'", - "qwer", - "uiop", - "tyur", - "zxcv", - "bnm", - }; -int n_groups; - -int main() -{ int choice, i; - char *test_array; - int ch = KEY_F1; - int mistakes; - int x, y; - time_t start_t, end_t; - WINDOW *typing_win; - char string[80]; - - string[0] = '\0'; - - initscr(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - intrflush(stdscr, FALSE); - - srandom(time(NULL)); - n_groups = sizeof(groups) / sizeof(char *); - test_array = (char *)calloc(HSIZE + 1, sizeof(char)); - - while(1) - { - if(ch == KEY_F1) - { choice = print_menu(); - choice -= 1; - if(choice == n_groups) - { print_byebye(); - free(test_array); - endwin(); - exit(0); - } - } - clear(); - strcpy(string, "Typing window"); - print_in_middle(STARTX, STARTY - 2, LENGTH, string, NULL); - attron(A_REVERSE); - mvprintw(STATUSY, STATUSX, "Press F1 to Main Menu"); - refresh(); - attroff(A_REVERSE); - - create_test_string(test_array, choice); - typing_win = newwin(WIDTH, LENGTH, STARTY, STARTX); - keypad(typing_win, TRUE); - intrflush(typing_win, FALSE); - box(typing_win, 0, 0); - - x = 1; - y = 1; - mvwprintw(typing_win, y, x, "%s", test_array); - wrefresh(typing_win); - y += 1; - - mistakes = 0; - i = 0; - time(&start_t); - wmove(typing_win, y, x); - wrefresh(typing_win); - ch = 0; - while(ch != KEY_F1 && i != HSIZE + 1) - { ch = wgetch(typing_win); - mvwprintw(typing_win, y, x, "%c", ch); - wrefresh(typing_win); - ++x; - if(ch == test_array[i]) - { ++i; - continue; - } - else - { ++mistakes; - ++i; - } - } - - time(&end_t); - print_time(start_t, end_t, mistakes); - } - free(test_array); - endwin(); - return 0; -} - - -int print_menu() -{ int choice, i; - - choice = 0; - while(1) - { clear(); - printw("\n\n"); - print_in_middle(1, 1, 0, "* * * Welcome to typing practice (Version 1.0) * * * ", NULL); - printw("\n\n\n"); - for(i = 0;i <= n_groups - 1; ++i) - printw("\t%3d: \tPractice %s\n", i + 1, groups[i]); - printw("\t%3d: \tExit\n", i + 1); - - printw("\n\n\tChoice: "); - refresh(); - echo(); - scanw("%d", &choice); - noecho(); - - if(choice >= 1 && choice <= n_groups + 1) - break; - else - { attron(A_REVERSE); - mvprintw(STATUSY, STATUSX, "Wrong choice\tPress any key to continue"); - attroff(A_REVERSE); - getch(); - } - } - return choice; -} - -void create_test_string(char *test_array, int choice) -{ int i, index, length; - - length = strlen(groups[choice]); - for(i = 0;i <= HSIZE - 1; ++i) - { if(i%5 == 0) - test_array[i] = ' '; - else - { index = (int)(random() % length); - test_array[i] = groups[choice][index]; - } - } - test_array[i] = '\0'; -} - -void print_byebye() -{ printw("\n"); - print_in_middle(0,0,0,"Thank you for using my typing tutor\n", NULL); - print_in_middle(0,0,0,"Bye Bye ! ! !\n", NULL); - refresh(); -} - -void print_time(time_t start_t, time_t end_t, int mistakes) -{ long int diff; - int h,m,s; - float wpm; - - diff = end_t - start_t; - wpm = ((HSIZE / 5)/(double)diff)*60; - - h = (int)(diff / 3600); - diff -= h * 3600; - m = (int)(diff / 60); - diff -= m * 60; - s = (int)diff; - - attron(A_REVERSE); - mvprintw(STATUSY, STATUSX, "Mistakes made : %d time taken: %d:%d:%d WPM : %.2f Press any Key to continue", mistakes, h, m, s, wpm); - attroff(A_REVERSE); - - refresh(); - getch(); - -} - -/* ---------------------------------------------------------------- * - * startx = 0 means at present x * - * starty = 0 means at present y * - * win = NULL means take stdscr * - * ---------------------------------------------------------------- */ - -void print_in_middle(int startx, int starty, int width, char *string, WINDOW *win) -{ int length, x, y; - float temp; - - if(win == NULL) - win = stdscr; - getyx(win, y, x); - if(startx != 0) - x = startx; - if(starty != 0) - y = starty; - if(width == 0) - width = 80; - - length = strlen(string); - temp = (width - length)/ 2; - x = startx + (int)temp; - mvwprintw(win, y, x, "%s", string); - refresh(); -} diff --git a/curses-practice/Makefile b/curses-practice/Makefile deleted file mode 100644 index 2d103e9..0000000 --- a/curses-practice/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -# The top level Makefile - -TOP := $(PWD) -PROJECTS := JustForFun basics forms menus panels - - -all: - $(foreach project,$(PROJECTS),\ - cd $(project) && \ - $(MAKE) && \ - cd $(TOP) \ - ;\ - ) - @echo - @echo "*********************************************" - @echo "All files Built" - @echo "Please move to demo/exe directory" - @echo "Execute each file to see examples in action" - @echo "*********************************************" - @echo - - -clean: - $(foreach project,$(PROJECTS),\ - cd $(project) && \ - $(MAKE) clean && \ - cd $(TOP) \ - ;\ - ) diff --git a/curses-practice/README b/curses-practice/README deleted file mode 100644 index e3a535a..0000000 --- a/curses-practice/README +++ /dev/null @@ -1,87 +0,0 @@ -This is the top level README file. -This directory is structured as follows: - -ncurses - | - |----> JustForFun -- just for fun programs - |----> basics -- basic programs - |----> demo -- output files go into this directory after make - | | - | |----> exe -- exe files of all example programs - |----> forms -- programs related to form library - |----> menus -- programs related to menus library - |----> panels -- programs related to panels library - |----> perl -- perl equivalents of the examples (contributed - | by Anuradha Ratnaweera) - |----> Makefile -- the top level Makefile - |----> README -- the top level README file. contains instructions - | -- to create executables for example programs - -To compile and install all example programs, just run make in this directory. - - make - -It installs all the exe files in demo/exe directory. You can go to that direcory -and see the examples in action. - -Have Fun !!! - -- Pradeep Padala - -Description of files in each directory --------------------------------------- -JustForFun - | - |----> hanoi.c -- The Towers of Hanoi Solver - |----> life.c -- The Game of Life demo - |----> magic.c -- An Odd Order Magic Square builder - |----> queens.c -- The famous N-Queens Solver - |----> shuffle.c -- A fun game, if you have time to kill - |----> tt.c -- A very trivial typing tutor - - basics - | - |----> acs_vars.c -- ACS_ variables example - |----> hello_world.c -- Simple "Hello World" Program - |----> init_func_example.c -- Initialization functions example - |----> key_code.c -- Shows the scan code of the key pressed - |----> mouse_menu.c -- A menu accessible by mouse - |----> other_border.c -- Shows usage of other border functions apart - | -- box() - |----> printw_example.c -- A very simple printw() example - |----> scanw_example.c -- A very simple getstr() example - |----> simple_attr.c -- A program that can print a c file with comments - | -- in attribute - |----> simple_color.c -- A simple example demonstrating colors - |----> simple_key.c -- A menu accessible with keyboard UP, DOWN arrows - |----> temp_leave.c -- Demonstrates temporarily leaving curses mode - |----> win_border.c -- Shows Creation of windows and borders - |----> with_chgat.c -- chgat() usage example - - forms - | - |----> form_attrib.c -- Usage of field attributes - |----> form_options.c -- Usage of field options - |----> form_simple.c -- A simple form example - |----> form_win.c -- Demo of windows associated with forms - - menus - | - |----> menu_attrib.c -- Usage of menu attributes - |----> menu_item_data.c -- Usage of item_name() etc.. functions - |----> menu_multi_column.c -- Creates multi columnar menus - |----> menu_scroll.c -- Demonstrates scrolling capability of menus - |----> menu_simple.c -- A simple menu accessed by arrow keys - |----> menu_toggle.c -- Creates multi valued menus and explains - | -- REQ_TOGGLE_ITEM - |----> menu_userptr.c -- Usage of user pointer - |----> menu_win.c -- Demo of windows associated with menus - - panels - | - |----> panel_browse.c -- Panel browsing through tab. Usage of user pointer - |----> panel_hide.c -- Hiding and Un hiding of panels - |----> panel_resize.c -- Moving and resizing of panels - |----> panel_simple.c -- A simple panel example - - perl - |----> 01-10.pl -- Perl equivalents of first ten example programs diff --git a/curses-practice/basics/Makefile b/curses-practice/basics/Makefile deleted file mode 100644 index 90ec1fb..0000000 --- a/curses-practice/basics/Makefile +++ /dev/null @@ -1,35 +0,0 @@ -# Makefile for JustForFun Files - -# A few variables - -CC=gcc -LIBS=-lncurses - -SRC_DIR=. -EXE_DIR=../demo/exe - -EXES = \ - ${EXE_DIR}/hello_world \ - ${EXE_DIR}/init_func_example \ - ${EXE_DIR}/key_code \ - ${EXE_DIR}/mouse_menu \ - ${EXE_DIR}/other_border \ - ${EXE_DIR}/printw_example \ - ${EXE_DIR}/scanw_example \ - ${EXE_DIR}/simple_attr \ - ${EXE_DIR}/simple_color \ - ${EXE_DIR}/simple_key \ - ${EXE_DIR}/temp_leave \ - ${EXE_DIR}/win_border \ - ${EXE_DIR}/with_chgat - -${EXE_DIR}/%: %.o - ${CC} -o $@ $< ${LIBS} - -%.o: ${SRC_DIR}/%.c - ${CC} -o $@ -c $< - -all: ${EXES} - -clean: - @rm -f ${EXES} diff --git a/curses-practice/basics/README b/curses-practice/basics/README deleted file mode 100644 index 0760867..0000000 --- a/curses-practice/basics/README +++ /dev/null @@ -1,20 +0,0 @@ -Description of files --------------------- - basics - | - |----> acs_vars.c -- ACS_ variables example - |----> hello_world.c -- Simple "Hello World" Program - |----> init_func_example.c -- Initialization functions example - |----> key_code.c -- Shows the scan code of the key pressed - |----> mouse_menu.c -- A menu accessible by mouse - |----> other_border.c -- Shows usage of other border functions apart - | -- box() - |----> printw_example.c -- A very simple printw() example - |----> scanw_example.c -- A very simple getstr() example - |----> simple_attr.c -- A program that can print a c file with comments - | -- in attribute - |----> simple_color.c -- A simple example demonstrating colors - |----> simple_key.c -- A menu accessible with keyboard UP, DOWN arrows - |----> temp_leave.c -- Demonstrates temporarily leaving curses mode - |----> win_border.c -- Shows Creation of windows and borders - |----> with_chgat.c -- chgat() usage example diff --git a/curses-practice/basics/acs_vars.c b/curses-practice/basics/acs_vars.c deleted file mode 100644 index 92db58c..0000000 --- a/curses-practice/basics/acs_vars.c +++ /dev/null @@ -1,44 +0,0 @@ -#include - -int main() -{ - initscr(); - - printw("Upper left corner "); addch(ACS_ULCORNER); printw("\n"); - printw("Lower left corner "); addch(ACS_LLCORNER); printw("\n"); - printw("Lower right corner "); addch(ACS_LRCORNER); printw("\n"); - printw("Tee pointing right "); addch(ACS_LTEE); printw("\n"); - printw("Tee pointing left "); addch(ACS_RTEE); printw("\n"); - printw("Tee pointing up "); addch(ACS_BTEE); printw("\n"); - printw("Tee pointing down "); addch(ACS_TTEE); printw("\n"); - printw("Horizontal line "); addch(ACS_HLINE); printw("\n"); - printw("Vertical line "); addch(ACS_VLINE); printw("\n"); - printw("Large Plus or cross over "); addch(ACS_PLUS); printw("\n"); - printw("Scan Line 1 "); addch(ACS_S1); printw("\n"); - printw("Scan Line 3 "); addch(ACS_S3); printw("\n"); - printw("Scan Line 7 "); addch(ACS_S7); printw("\n"); - printw("Scan Line 9 "); addch(ACS_S9); printw("\n"); - printw("Diamond "); addch(ACS_DIAMOND); printw("\n"); - printw("Checker board (stipple) "); addch(ACS_CKBOARD); printw("\n"); - printw("Degree Symbol "); addch(ACS_DEGREE); printw("\n"); - printw("Plus/Minus Symbol "); addch(ACS_PLMINUS); printw("\n"); - printw("Bullet "); addch(ACS_BULLET); printw("\n"); - printw("Arrow Pointing Left "); addch(ACS_LARROW); printw("\n"); - printw("Arrow Pointing Right "); addch(ACS_RARROW); printw("\n"); - printw("Arrow Pointing Down "); addch(ACS_DARROW); printw("\n"); - printw("Arrow Pointing Up "); addch(ACS_UARROW); printw("\n"); - printw("Board of squares "); addch(ACS_BOARD); printw("\n"); - printw("Lantern Symbol "); addch(ACS_LANTERN); printw("\n"); - printw("Solid Square Block "); addch(ACS_BLOCK); printw("\n"); - printw("Less/Equal sign "); addch(ACS_LEQUAL); printw("\n"); - printw("Greater/Equal sign "); addch(ACS_GEQUAL); printw("\n"); - printw("Pi "); addch(ACS_PI); printw("\n"); - printw("Not equal "); addch(ACS_NEQUAL); printw("\n"); - printw("UK pound sign "); addch(ACS_STERLING); printw("\n"); - - refresh(); - getch(); - endwin(); - - return 0; -} diff --git a/curses-practice/basics/hello_world.c b/curses-practice/basics/hello_world.c deleted file mode 100644 index 4ddd229..0000000 --- a/curses-practice/basics/hello_world.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -int main() -{ - initscr(); - printw("Hello World !!!"); - refresh(); - getch(); - endwin(); - - return 0; -} diff --git a/curses-practice/basics/hello_world.py b/curses-practice/basics/hello_world.py deleted file mode 100644 index 3c3ffc7..0000000 --- a/curses-practice/basics/hello_world.py +++ /dev/null @@ -1,18 +0,0 @@ -from __future__ import print_function -import sys -import curses - - -def hello_world(stdscr): - stdscr.addstr(0, 0, "Hello World !!!") - stdscr.refresh() - stdscr.getch() - - -def main(): - curses.wrapper(hello_world) - return 0 - - -if __name__ == '__main__': - sys.exit(main()) diff --git a/curses-practice/basics/init_func_example.c b/curses-practice/basics/init_func_example.c deleted file mode 100644 index a453f99..0000000 --- a/curses-practice/basics/init_func_example.c +++ /dev/null @@ -1,37 +0,0 @@ -#include - -void _do_setup(){ - initscr(); - raw(); - keypad(stdscr, TRUE); - noecho(); -} - - -void _display_and_quit(){ - refresh(); - getch(); - endwin(); -} - - -int main() -{ - int ch; - _do_setup(); - - printw("Type any character to see it in bold\n"); - ch = getch(); - if(ch == KEY_F(1)){ - printw("F1 Key pressed"); - } else { - printw("The pressed key is "); - attron(A_BOLD); - printw("%c", ch); - attroff(A_BOLD); - } - - _display_and_quit(); - - return 0; -} diff --git a/curses-practice/basics/init_func_example.py b/curses-practice/basics/init_func_example.py deleted file mode 100644 index e1d86eb..0000000 --- a/curses-practice/basics/init_func_example.py +++ /dev/null @@ -1,33 +0,0 @@ -import sys -import curses - - -def main(): - curses.wrapper(init_func_example) - return 0 - - -def init_func_example(stdscr): - curses.raw() - stdscr.keypad(1) - curses.noecho() - stdscr.addstr(0, 0, "Type any character to see it in bold\n") - - ch = stdscr.getch() - if ch == curses.KEY_F1: - stdscr.addstr(1, 0, "F1 Key pressed") - else: - key_pressed = "The pressed key is " - stdscr.addstr(1, 0, key_pressed) - stdscr.attron(curses.A_BOLD) - stdscr.addstr(1, len(key_pressed), chr(ch)) - stdscr.attroff(curses.A_BOLD) - - stdscr.refresh() - stdscr.getch() - - -if __name__ == '__main__': - sys.exit(main()) - -# vim:filetype=python diff --git a/curses-practice/basics/key_code.c b/curses-practice/basics/key_code.c deleted file mode 100644 index 5ad80eb..0000000 --- a/curses-practice/basics/key_code.c +++ /dev/null @@ -1,14 +0,0 @@ -#include - -int main() -{ int ch; - - initscr(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - - ch = getch(); - endwin(); - printf("The key pressed is %d\n", ch); -} diff --git a/curses-practice/basics/mouse_menu.c b/curses-practice/basics/mouse_menu.c deleted file mode 100644 index 6008092..0000000 --- a/curses-practice/basics/mouse_menu.c +++ /dev/null @@ -1,106 +0,0 @@ -#include - -#define WIDTH 30 -#define HEIGHT 10 - -int startx = 0; -int starty = 0; - -char *choices[] = { "Choice 1", - "Choice 2", - "Choice 3", - "Choice 4", - "Exit", - }; - -int n_choices = sizeof(choices) / sizeof(char *); - -void print_menu(WINDOW *menu_win, int highlight); -void report_choice(int mouse_x, int mouse_y, int *p_choice); - -int main() -{ int c, choice = 0; - WINDOW *menu_win; - MEVENT event; - - /* Initialize curses */ - initscr(); - clear(); - noecho(); - cbreak(); //Line buffering disabled. pass on everything - - /* Try to put the window in the middle of screen */ - startx = (80 - WIDTH) / 2; - starty = (24 - HEIGHT) / 2; - - attron(A_REVERSE); - mvprintw(23, 1, "Click on Exit to quit (Works best in a virtual console)"); - refresh(); - attroff(A_REVERSE); - - /* Print the menu for the first time */ - menu_win = newwin(HEIGHT, WIDTH, starty, startx); - print_menu(menu_win, 1); - /* Get all the mouse events */ - mousemask(ALL_MOUSE_EVENTS, NULL); - - while(1) - { c = wgetch(menu_win); - switch(c) - { case KEY_MOUSE: - if(getmouse(&event) == OK) - { /* When the user clicks left mouse button */ - if(event.bstate & BUTTON1_PRESSED) - { report_choice(event.x + 1, event.y + 1, &choice); - if(choice == -1) //Exit chosen - goto end; - mvprintw(22, 1, "Choice made is : %d String Chosen is \"%10s\"", choice, choices[choice - 1]); - refresh(); - } - } - print_menu(menu_win, choice); - break; - } - } -end: - endwin(); - return 0; -} - - -void print_menu(WINDOW *menu_win, int highlight) -{ - int x, y, i; - - x = 2; - y = 2; - box(menu_win, 0, 0); - for(i = 0; i < n_choices; ++i) - { if(highlight == i + 1) - { wattron(menu_win, A_REVERSE); - mvwprintw(menu_win, y, x, "%s", choices[i]); - wattroff(menu_win, A_REVERSE); - } - else - mvwprintw(menu_win, y, x, "%s", choices[i]); - ++y; - } - wrefresh(menu_win); -} - -/* Report the choice according to mouse position */ -void report_choice(int mouse_x, int mouse_y, int *p_choice) -{ int i,j, choice; - - i = startx + 2; - j = starty + 3; - - for(choice = 0; choice < n_choices; ++choice) - if(mouse_y == j + choice && mouse_x >= i && mouse_x <= i + strlen(choices[choice])) - { if(choice == n_choices - 1) - *p_choice = -1; - else - *p_choice = choice + 1; - break; - } -} diff --git a/curses-practice/basics/other_border.c b/curses-practice/basics/other_border.c deleted file mode 100644 index 8252631..0000000 --- a/curses-practice/basics/other_border.c +++ /dev/null @@ -1,120 +0,0 @@ -#include - -typedef struct _win_border_struct { - chtype ls, rs, ts, bs, - tl, tr, bl, br; -}WIN_BORDER; - -typedef struct _WIN_struct { - - int startx, starty; - int height, width; - WIN_BORDER border; -}WIN; - -void init_win_params(WIN *p_win); -void print_win_params(WIN *p_win); -void create_box(WIN *win, bool flag); - -int main(int argc, char *argv[]) -{ WIN win; - int ch; - - initscr(); /* Start curses mode */ - start_color(); /* Start the color functionality */ - cbreak(); /* Line buffering disabled, Pass on - * everty thing to me */ - keypad(stdscr, TRUE); /* I need that nifty F1 */ - noecho(); - init_pair(1, COLOR_CYAN, COLOR_BLACK); - - /* Initialize the window parameters */ - init_win_params(&win); - print_win_params(&win); - - attron(COLOR_PAIR(1)); - printw("Press F1 to exit"); - refresh(); - attroff(COLOR_PAIR(1)); - - create_box(&win, TRUE); - while((ch = getch()) != KEY_F(1)) - { switch(ch) - { case KEY_LEFT: - create_box(&win, FALSE); - --win.startx; - create_box(&win, TRUE); - break; - case KEY_RIGHT: - create_box(&win, FALSE); - ++win.startx; - create_box(&win, TRUE); - break; - case KEY_UP: - create_box(&win, FALSE); - --win.starty; - create_box(&win, TRUE); - break; - case KEY_DOWN: - create_box(&win, FALSE); - ++win.starty; - create_box(&win, TRUE); - break; - } - } - endwin(); /* End curses mode */ - return 0; -} -void init_win_params(WIN *p_win) -{ - p_win->height = 3; - p_win->width = 10; - p_win->starty = (LINES - p_win->height)/2; - p_win->startx = (COLS - p_win->width)/2; - - p_win->border.ls = '|'; - p_win->border.rs = '|'; - p_win->border.ts = '-'; - p_win->border.bs = '-'; - p_win->border.tl = '+'; - p_win->border.tr = '+'; - p_win->border.bl = '+'; - p_win->border.br = '+'; - -} -void print_win_params(WIN *p_win) -{ -#ifdef _DEBUG - mvprintw(25, 0, "%d %d %d %d", p_win->startx, p_win->starty, - p_win->width, p_win->height); - refresh(); -#endif -} -void create_box(WIN *p_win, bool flag) -{ int i, j; - int x, y, w, h; - - x = p_win->startx; - y = p_win->starty; - w = p_win->width; - h = p_win->height; - - if(flag == TRUE) - { mvaddch(y, x, p_win->border.tl); - mvaddch(y, x + w, p_win->border.tr); - mvaddch(y + h, x, p_win->border.bl); - mvaddch(y + h, x + w, p_win->border.br); - mvhline(y, x + 1, p_win->border.ts, w - 1); - mvhline(y + h, x + 1, p_win->border.bs, w - 1); - mvvline(y + 1, x, p_win->border.ls, h - 1); - mvvline(y + 1, x + w, p_win->border.rs, h - 1); - - } - else - for(j = y; j <= y + h; ++j) - for(i = x; i <= x + w; ++i) - mvaddch(j, i, ' '); - - refresh(); - -} diff --git a/curses-practice/basics/printw_example.c b/curses-practice/basics/printw_example.c deleted file mode 100644 index 310c40d..0000000 --- a/curses-practice/basics/printw_example.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include - -int main() -{ - char mesg[] = "Just a string"; - int row, col; - - initscr(); - getmaxyx(stdscr, row, col); - mvprintw(row / 2, (col - strlen(mesg)) / 2, "%s", mesg); - mvprintw(row - 2, 0, "This screen has %d rows and %d columns\n", row, col); - printw("Try resizing your window (if possible) and then run this program again"); - refresh(); - getch(); - endwin(); - - return 0; -} diff --git a/curses-practice/basics/printw_example.py b/curses-practice/basics/printw_example.py deleted file mode 100644 index 1770617..0000000 --- a/curses-practice/basics/printw_example.py +++ /dev/null @@ -1,25 +0,0 @@ -import sys -import curses - - -def printw_example(stdscr): - mesg = "Just a string" - row, col = stdscr.getmaxyx() - stdscr.addstr(row / 2, (col - len(mesg)) / 2, mesg) - stdscr.addstr(row - 2, 0, "This screen has {0} rows and {1} " - "columns\n".format(row, col)) - stdscr.addstr(row - 1, 0, "Try resizing your window (if possible) and then" - "run this program again") - stdscr.refresh() - stdscr.getch() - - -def main(): - curses.wrapper(printw_example) - return 0 - - -if __name__ == '__main__': - sys.exit(main()) - -# vim:filetype=python diff --git a/curses-practice/basics/scanw_example.c b/curses-practice/basics/scanw_example.c deleted file mode 100644 index a81f053..0000000 --- a/curses-practice/basics/scanw_example.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include - -int main() -{ - char * mesg = "Enter a string: "; - char str[80]; - int row, col; - - initscr(); - getmaxyx(stdscr, row, col); - mvprintw(row / 2, (col - strlen(mesg)) / 2, "%s", mesg); - getstr(str); - mvprintw(LINES - 2, 0, "You Entered: %s", str); - getch(); - endwin(); - - return 0; -} diff --git a/curses-practice/basics/scanw_example.py b/curses-practice/basics/scanw_example.py deleted file mode 100644 index 7d68764..0000000 --- a/curses-practice/basics/scanw_example.py +++ /dev/null @@ -1,24 +0,0 @@ -import sys -import curses - - -def scanw_example(stdscr): - mesg = 'Enter a string: ' - - row, col = stdscr.getmaxyx() - curses.echo() - stdscr.addstr(row / 2, (col - len(mesg)) / 2, mesg) - instr = stdscr.getstr() - stdscr.addstr(row - 2, 0, 'You Entered: {0}'.format(instr)) - stdscr.getch() - - -def main(): - curses.wrapper(scanw_example) - return 0 - - -if __name__ == '__main__': - sys.exit(main()) - -# vim:filetype=python diff --git a/curses-practice/basics/simple_attr.c b/curses-practice/basics/simple_attr.c deleted file mode 100644 index 2a4ec2d..0000000 --- a/curses-practice/basics/simple_attr.c +++ /dev/null @@ -1,56 +0,0 @@ -/* pager functionality by Joseph Spainhour" */ -#include -#include - -int main(int argc, char *argv[]) -{ - int ch, prev, row, col; - prev = EOF; - FILE *fp; - int y, x; - - if(argc != 2) - { - printf("Usage: %s \n", argv[0]); - exit(1); - } - fp = fopen(argv[1], "r"); - if(fp == NULL) - { - perror("Cannot open input file"); - exit(1); - } - initscr(); /* Start curses mode */ - getmaxyx(stdscr, row, col); /* find the boundaries of the screeen */ - while((ch = fgetc(fp)) != EOF) /* read the file till we reach the end */ - { - getyx(stdscr, y, x); /* get the current curser position */ - if(y == (row - 1)) /* are we are at the end of the screen */ - { - printw("<-Press Any Key->"); /* tell the user to press a key */ - getch(); - clear(); /* clear the screen */ - move(0, 0); /* start at the beginning of the screen */ - } - if(prev == '/' && ch == '*') /* If it is / and * then only - * switch bold on */ - { - attron(A_BOLD); /* cut bold on */ - getyx(stdscr, y, x); /* get the current curser position */ - move(y, x - 1); /* back up one space */ - printw("%c%c", '/', ch); /* The actual printing is done here */ - } else { - printw("%c", ch); - } - refresh(); - - if(prev == '*' && ch == '/') { - attroff(A_BOLD); /* Switch it off once we got */ - } - /* and then / */ - prev = ch; - } - endwin(); /* End curses mode */ - fclose(fp); - return 0; -} diff --git a/curses-practice/basics/simple_attr.py b/curses-practice/basics/simple_attr.py deleted file mode 100644 index efd61a2..0000000 --- a/curses-practice/basics/simple_attr.py +++ /dev/null @@ -1,50 +0,0 @@ -from __future__ import print_function -import sys -import curses - -FILE = {'fp': None} - - -def simple_attr(stdscr): - row, col = stdscr.getmaxyx() - prev = '' - fp = FILE['fp'] - for line in fp: - for ch in line: - y, x = stdscr.getyx() - if y == (row - 1): - stdscr.addstr(row - 1, 0, "<-Press Any Key->") - stdscr.getch() - stdscr.clear() - stdscr.move(0, 0) - elif prev == '/' and ch == '*': - stdscr.attron(curses.A_BOLD) - y, x = stdscr.getyx() - stdscr.addstr(y, x - 1, '/{0}'.format(ch)) - else: - stdscr.addstr(y, x, ch) - stdscr.refresh() - - if prev == '*' and ch == '/': - stdscr.attroff(curses.A_BOLD) - - prev = ch - - -def main(sysargs=sys.argv[:]): - if not sysargs[1:]: - print('Usage: {0} '.format(sysargs[0])) - return 1 - try: - FILE['fp'] = open(sysargs[1], 'r') - except (OSError, IOError): - print('Cannot open input file', file=sys.stderr) - return 1 - curses.wrapper(simple_attr) - return 0 - - -if __name__ == '__main__': - sys.exit(main()) - -# vim:filetype=python diff --git a/curses-practice/basics/simple_color.c b/curses-practice/basics/simple_color.c deleted file mode 100644 index 45223db..0000000 --- a/curses-practice/basics/simple_color.c +++ /dev/null @@ -1,40 +0,0 @@ -#include - -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string); -int main(int argc, char *argv[]) -{ initscr(); /* Start curses mode */ - if(has_colors() == FALSE) - { endwin(); - printf("Your terminal does not support color\n"); - exit(1); - } - start_color(); /* Start color */ - init_pair(1, COLOR_RED, COLOR_BLACK); - - attron(COLOR_PAIR(1)); - print_in_middle(stdscr, LINES / 2, 0, 0, "Viola !!! In color ..."); - attroff(COLOR_PAIR(1)); - getch(); - endwin(); -} -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string) -{ int length, x, y; - float temp; - - if(win == NULL) - win = stdscr; - getyx(win, y, x); - if(startx != 0) - x = startx; - if(starty != 0) - y = starty; - if(width == 0) - width = 80; - - length = strlen(string); - temp = (width - length)/ 2; - x = startx + (int)temp; - mvwprintw(win, y, x, "%s", string); - refresh(); -} - diff --git a/curses-practice/basics/simple_key.c b/curses-practice/basics/simple_key.c deleted file mode 100644 index 23ff44c..0000000 --- a/curses-practice/basics/simple_key.c +++ /dev/null @@ -1,92 +0,0 @@ -#include -#include - -#define WIDTH 30 -#define HEIGHT 10 - -int startx = 0; -int starty = 0; - -char *choices[] = { - "Choice 1", - "Choice 2", - "Choice 3", - "Choice 4", - "Exit", - }; -int n_choices = sizeof(choices) / sizeof(char *); -void print_menu(WINDOW *menu_win, int highlight); - -int main() -{ WINDOW *menu_win; - int highlight = 1; - int choice = 0; - int c; - - initscr(); - clear(); - noecho(); - cbreak(); /* Line buffering disabled. pass on everything */ - startx = (80 - WIDTH) / 2; - starty = (24 - HEIGHT) / 2; - - menu_win = newwin(HEIGHT, WIDTH, starty, startx); - keypad(menu_win, TRUE); - mvprintw(0, 0, "Use arrow keys to go up and down, Press enter to select a choice"); - refresh(); - print_menu(menu_win, highlight); - while(1) - { c = wgetch(menu_win); - switch(c) - { case KEY_UP: - if(highlight == 1) - highlight = n_choices; - else - --highlight; - break; - case KEY_DOWN: - if(highlight == n_choices) - highlight = 1; - else - ++highlight; - break; - case 10: - choice = highlight; - break; - default: - mvprintw(24, 0, "Charcter pressed is = %3d Hopefully it can be printed as '%c'", c, c); - refresh(); - break; - } - print_menu(menu_win, highlight); - if(choice != 0) /* User did a choice come out of the infinite loop */ - break; - } - mvprintw(23, 0, "You chose choice %d with choice string %s\n", choice, choices[choice - 1]); - clrtoeol(); - refresh(); - endwin(); - return 0; -} - - -void print_menu(WINDOW *menu_win, int highlight) -{ - int x, y, i; - - x = 2; - y = 2; - box(menu_win, 0, 0); - for(i = 0; i < n_choices; ++i) - { if(highlight == i + 1) /* High light the present choice */ - { wattron(menu_win, A_REVERSE); - mvwprintw(menu_win, y, x, "%s", choices[i]); - wattroff(menu_win, A_REVERSE); - } - else - mvwprintw(menu_win, y, x, "%s", choices[i]); - ++y; - } - wrefresh(menu_win); -} - diff --git a/curses-practice/basics/temp_leave.c b/curses-practice/basics/temp_leave.c deleted file mode 100644 index 8ba21c1..0000000 --- a/curses-practice/basics/temp_leave.c +++ /dev/null @@ -1,20 +0,0 @@ -#include - -int main() -{ - initscr(); /* Start curses mode */ - printw("Hello World !!!\n"); /* Print Hello World */ - refresh(); /* Print it on to the real screen */ - def_prog_mode(); /* Save the tty modes */ - endwin(); /* End curses mode temporarily */ - system("/bin/sh"); /* Do whatever you like in cooked mode */ - reset_prog_mode(); /* Return to the previous tty mode*/ - /* stored by def_prog_mode() */ - refresh(); /* Do refresh() to restore the */ - /* Screen contents */ - printw("Another String\n"); /* Back to curses use the full */ - refresh(); /* capabilities of curses */ - endwin(); /* End curses mode */ - - return 0; -} diff --git a/curses-practice/basics/win_border.c b/curses-practice/basics/win_border.c deleted file mode 100644 index b0e8d61..0000000 --- a/curses-practice/basics/win_border.c +++ /dev/null @@ -1,82 +0,0 @@ -#include - - -WINDOW *create_newwin(int height, int width, int starty, int startx); -void destroy_win(WINDOW *local_win); - -int main(int argc, char *argv[]) -{ WINDOW *my_win; - int startx, starty, width, height; - int ch; - - initscr(); /* Start curses mode */ - cbreak(); /* Line buffering disabled, Pass on - * everty thing to me */ - keypad(stdscr, TRUE); /* I need that nifty F1 */ - - height = 3; - width = 10; - starty = (LINES - height) / 2; /* Calculating for a center placement */ - startx = (COLS - width) / 2; /* of the window */ - printw("Press F1 to exit"); - refresh(); - my_win = create_newwin(height, width, starty, startx); - - while((ch = getch()) != KEY_F(1)) - { switch(ch) - { case KEY_LEFT: - destroy_win(my_win); - my_win = create_newwin(height, width, starty,--startx); - break; - case KEY_RIGHT: - destroy_win(my_win); - my_win = create_newwin(height, width, starty,++startx); - break; - case KEY_UP: - destroy_win(my_win); - my_win = create_newwin(height, width, --starty,startx); - break; - case KEY_DOWN: - destroy_win(my_win); - my_win = create_newwin(height, width, ++starty,startx); - break; - } - } - - endwin(); /* End curses mode */ - return 0; -} - -WINDOW *create_newwin(int height, int width, int starty, int startx) -{ WINDOW *local_win; - - local_win = newwin(height, width, starty, startx); - box(local_win, 0 , 0); /* 0, 0 gives default characters - * for the vertical and horizontal - * lines */ - wrefresh(local_win); /* Show that box */ - - return local_win; -} - -void destroy_win(WINDOW *local_win) -{ - /* box(local_win, ' ', ' '); : This won't produce the desired - * result of erasing the window. It will leave it's four corners - * and so an ugly remnant of window. - */ - wborder(local_win, ' ', ' ', ' ',' ',' ',' ',' ',' '); - /* The parameters taken are - * 1. win: the window on which to operate - * 2. ls: character to be used for the left side of the window - * 3. rs: character to be used for the right side of the window - * 4. ts: character to be used for the top side of the window - * 5. bs: character to be used for the bottom side of the window - * 6. tl: character to be used for the top left corner of the window - * 7. tr: character to be used for the top right corner of the window - * 8. bl: character to be used for the bottom left corner of the window - * 9. br: character to be used for the bottom right corner of the window - */ - wrefresh(local_win); - delwin(local_win); -} diff --git a/curses-practice/basics/with_chgat.c b/curses-practice/basics/with_chgat.c deleted file mode 100644 index 7d347c6..0000000 --- a/curses-practice/basics/with_chgat.c +++ /dev/null @@ -1,15 +0,0 @@ -#include - -int main(int argc, char *argv[]) -{ - initscr(); - start_color(); - - init_pair(1, COLOR_CYAN, COLOR_BLACK); - printw("A Big string which i didn't care to type fully "); - mvchgat(0, 0, -1, A_BLINK, 1, NULL); - refresh(); - getch(); - endwin(); - return 0; -} diff --git a/curses-practice/basics/with_chgat.py b/curses-practice/basics/with_chgat.py deleted file mode 100644 index 8b16b07..0000000 --- a/curses-practice/basics/with_chgat.py +++ /dev/null @@ -1,21 +0,0 @@ -import sys -import curses - - -def with_chgat(stdscr): - curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) - stdscr.addstr("A Big string which i didn't care to type fully ", - curses.color_pair(1) | curses.A_BLINK) - stdscr.refresh() - stdscr.getch() - - -def main(): - curses.wrapper(with_chgat) - return 0 - - -if __name__ == '__main__': - sys.exit(main()) - -# vim:filetype=python diff --git a/curses-practice/demo/exe/.placeholder b/curses-practice/demo/exe/.placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/curses-practice/forms/Makefile b/curses-practice/forms/Makefile deleted file mode 100644 index 4ed1b98..0000000 --- a/curses-practice/forms/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -# Makefile for JustForFun Files - -# A few variables - -CC=gcc -LIBS=-lform -lncurses - -SRC_DIR=. -EXE_DIR=../demo/exe - -EXES = \ - ${EXE_DIR}/form_attrib\ - ${EXE_DIR}/form_options\ - ${EXE_DIR}/form_simple\ - ${EXE_DIR}/form_win \ - -${EXE_DIR}/%: %.o - ${CC} -o $@ $< ${LIBS} - -%.o: ${SRC_DIR}/%.c - ${CC} -o $@ -c $< - -all: ${EXES} - - -clean: - @rm -f ${EXES} diff --git a/curses-practice/forms/README b/curses-practice/forms/README deleted file mode 100644 index 6e9a218..0000000 --- a/curses-practice/forms/README +++ /dev/null @@ -1,9 +0,0 @@ -Description of files --------------------- - forms - | - |----> form_attrib.c -- Usage of field attributes - |----> form_options.c -- Usage of field options - |----> form_simple.c -- A simple form example - |----> form_win.c -- Demo of windows associated with forms - diff --git a/curses-practice/forms/form_attrib.c b/curses-practice/forms/form_attrib.c deleted file mode 100644 index 93e1632..0000000 --- a/curses-practice/forms/form_attrib.c +++ /dev/null @@ -1,75 +0,0 @@ -#include - -int main() -{ FIELD *field[3]; - FORM *my_form; - int ch; - - /* Initialize curses */ - initscr(); - start_color(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - - /* Initialize few color pairs */ - init_pair(1, COLOR_WHITE, COLOR_BLUE); - init_pair(2, COLOR_WHITE, COLOR_BLUE); - - /* Initialize the fields */ - field[0] = new_field(1, 10, 4, 18, 0, 0); - field[1] = new_field(1, 10, 6, 18, 0, 0); - field[2] = NULL; - - /* Set field options */ - set_field_fore(field[0], COLOR_PAIR(1));/* Put the field with blue background */ - set_field_back(field[0], COLOR_PAIR(2));/* and white foreground (characters */ - /* are printed in white */ - field_opts_off(field[0], O_AUTOSKIP); /* Don't go to next field when this */ - /* Field is filled up */ - set_field_back(field[1], A_UNDERLINE); - field_opts_off(field[1], O_AUTOSKIP); - - /* Create the form and post it */ - my_form = new_form(field); - post_form(my_form); - refresh(); - - set_current_field(my_form, field[0]); /* Set focus to the colored field */ - mvprintw(4, 10, "Value 1:"); - mvprintw(6, 10, "Value 2:"); - mvprintw(LINES - 2, 0, "Use UP, DOWN arrow keys to switch between fields"); - refresh(); - - /* Loop through to get user requests */ - while((ch = getch()) != KEY_F(1)) - { switch(ch) - { case KEY_DOWN: - /* Go to next field */ - form_driver(my_form, REQ_NEXT_FIELD); - /* Go to the end of the present buffer */ - /* Leaves nicely at the last character */ - form_driver(my_form, REQ_END_LINE); - break; - case KEY_UP: - /* Go to previous field */ - form_driver(my_form, REQ_PREV_FIELD); - form_driver(my_form, REQ_END_LINE); - break; - default: - /* If this is a normal character, it gets */ - /* Printed */ - form_driver(my_form, ch); - break; - } - } - - /* Un post form and free the memory */ - unpost_form(my_form); - free_form(my_form); - free_field(field[0]); - free_field(field[1]); - - endwin(); - return 0; -} diff --git a/curses-practice/forms/form_options.c b/curses-practice/forms/form_options.c deleted file mode 100644 index b9ef831..0000000 --- a/curses-practice/forms/form_options.c +++ /dev/null @@ -1,76 +0,0 @@ -#include - -#define STARTX 15 -#define STARTY 4 -#define WIDTH 25 - -#define N_FIELDS 3 - -int main() -{ FIELD *field[N_FIELDS]; - FORM *my_form; - int ch, i; - - /* Initialize curses */ - initscr(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - - /* Initialize the fields */ - for(i = 0; i < N_FIELDS - 1; ++i) - field[i] = new_field(1, WIDTH, STARTY + i * 2, STARTX, 0, 0); - field[N_FIELDS - 1] = NULL; - - /* Set field options */ - set_field_back(field[1], A_UNDERLINE); /* Print a line for the option */ - - field_opts_off(field[0], O_ACTIVE); /* This field is a static label */ - field_opts_off(field[1], O_PUBLIC); /* This filed is like a password field*/ - field_opts_off(field[1], O_AUTOSKIP); /* To avoid entering the same field */ - /* after last character is entered */ - - /* Create the form and post it */ - my_form = new_form(field); - post_form(my_form); - refresh(); - - set_field_just(field[0], JUSTIFY_CENTER); /* Center Justification */ - set_field_buffer(field[0], 0, "This is a static Field"); - /* Initialize the field */ - mvprintw(STARTY, STARTX - 10, "Field 1:"); - mvprintw(STARTY + 2, STARTX - 10, "Field 2:"); - refresh(); - - /* Loop through to get user requests */ - while((ch = getch()) != KEY_F(1)) - { switch(ch) - { case KEY_DOWN: - /* Go to next field */ - form_driver(my_form, REQ_NEXT_FIELD); - /* Go to the end of the present buffer */ - /* Leaves nicely at the last character */ - form_driver(my_form, REQ_END_LINE); - break; - case KEY_UP: - /* Go to previous field */ - form_driver(my_form, REQ_PREV_FIELD); - form_driver(my_form, REQ_END_LINE); - break; - default: - /* If this is a normal character, it gets */ - /* Printed */ - form_driver(my_form, ch); - break; - } - } - - /* Un post form and free the memory */ - unpost_form(my_form); - free_form(my_form); - free_field(field[0]); - free_field(field[1]); - - endwin(); - return 0; -} diff --git a/curses-practice/forms/form_simple.c b/curses-practice/forms/form_simple.c deleted file mode 100644 index 63f7fe5..0000000 --- a/curses-practice/forms/form_simple.c +++ /dev/null @@ -1,66 +0,0 @@ -#include - -int main() -{ FIELD *field[3]; - FORM *my_form; - int ch; - - /* Initialize curses */ - initscr(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - - /* Initialize the fields */ - field[0] = new_field(1, 10, 4, 18, 0, 0); - field[1] = new_field(1, 10, 6, 18, 0, 0); - field[2] = NULL; - - /* Set field options */ - set_field_back(field[0], A_UNDERLINE); /* Print a line for the option */ - field_opts_off(field[0], O_AUTOSKIP); /* Don't go to next field when this */ - /* Field is filled up */ - set_field_back(field[1], A_UNDERLINE); - field_opts_off(field[1], O_AUTOSKIP); - - /* Create the form and post it */ - my_form = new_form(field); - post_form(my_form); - refresh(); - - mvprintw(4, 10, "Value 1:"); - mvprintw(6, 10, "Value 2:"); - refresh(); - - /* Loop through to get user requests */ - while((ch = getch()) != KEY_F(1)) - { switch(ch) - { case KEY_DOWN: - /* Go to next field */ - form_driver(my_form, REQ_NEXT_FIELD); - /* Go to the end of the present buffer */ - /* Leaves nicely at the last character */ - form_driver(my_form, REQ_END_LINE); - break; - case KEY_UP: - /* Go to previous field */ - form_driver(my_form, REQ_PREV_FIELD); - form_driver(my_form, REQ_END_LINE); - break; - default: - /* If this is a normal character, it gets */ - /* Printed */ - form_driver(my_form, ch); - break; - } - } - - /* Un post form and free the memory */ - unpost_form(my_form); - free_form(my_form); - free_field(field[0]); - free_field(field[1]); - - endwin(); - return 0; -} diff --git a/curses-practice/forms/form_win.c b/curses-practice/forms/form_win.c deleted file mode 100644 index 8cd3b16..0000000 --- a/curses-practice/forms/form_win.c +++ /dev/null @@ -1,112 +0,0 @@ -#include - -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color); - -int main() -{ - FIELD *field[3]; - FORM *my_form; - WINDOW *my_form_win; - int ch, rows, cols; - - /* Initialize curses */ - initscr(); - start_color(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - - /* Initialize few color pairs */ - init_pair(1, COLOR_RED, COLOR_BLACK); - - /* Initialize the fields */ - field[0] = new_field(1, 10, 6, 1, 0, 0); - field[1] = new_field(1, 10, 8, 1, 0, 0); - field[2] = NULL; - - /* Set field options */ - set_field_back(field[0], A_UNDERLINE); - field_opts_off(field[0], O_AUTOSKIP); /* Don't go to next field when this */ - /* Field is filled up */ - set_field_back(field[1], A_UNDERLINE); - field_opts_off(field[1], O_AUTOSKIP); - - /* Create the form and post it */ - my_form = new_form(field); - - /* Calculate the area required for the form */ - scale_form(my_form, &rows, &cols); - - /* Create the window to be associated with the form */ - my_form_win = newwin(rows + 4, cols + 4, 4, 4); - keypad(my_form_win, TRUE); - - /* Set main window and sub window */ - set_form_win(my_form, my_form_win); - set_form_sub(my_form, derwin(my_form_win, rows, cols, 2, 2)); - - /* Print a border around the main window and print a title */ - box(my_form_win, 0, 0); - print_in_middle(my_form_win, 1, 0, cols + 4, "My Form", COLOR_PAIR(1)); - - post_form(my_form); - wrefresh(my_form_win); - - mvprintw(LINES - 2, 0, "Use UP, DOWN arrow keys to switch between fields"); - refresh(); - - /* Loop through to get user requests */ - while((ch = wgetch(my_form_win)) != KEY_F(1)) - { switch(ch) - { case KEY_DOWN: - /* Go to next field */ - form_driver(my_form, REQ_NEXT_FIELD); - /* Go to the end of the present buffer */ - /* Leaves nicely at the last character */ - form_driver(my_form, REQ_END_LINE); - break; - case KEY_UP: - /* Go to previous field */ - form_driver(my_form, REQ_PREV_FIELD); - form_driver(my_form, REQ_END_LINE); - break; - default: - /* If this is a normal character, it gets */ - /* Printed */ - form_driver(my_form, ch); - break; - } - } - - /* Un post form and free the memory */ - unpost_form(my_form); - free_form(my_form); - free_field(field[0]); - free_field(field[1]); - - endwin(); - return 0; -} - -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color) -{ int length, x, y; - float temp; - - if(win == NULL) - win = stdscr; - getyx(win, y, x); - if(startx != 0) - x = startx; - if(starty != 0) - y = starty; - if(width == 0) - width = 80; - - length = strlen(string); - temp = (width - length)/ 2; - x = startx + (int)temp; - wattron(win, color); - mvwprintw(win, y, x, "%s", string); - wattroff(win, color); - refresh(); -} diff --git a/curses-practice/menus/Makefile b/curses-practice/menus/Makefile deleted file mode 100644 index 73626e7..0000000 --- a/curses-practice/menus/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -# Makefile for JustForFun Files - -# A few variables - -CC=gcc -LIBS=-lmenu -lncurses - -SRC_DIR=. -EXE_DIR=../demo/exe - -EXES = \ - ${EXE_DIR}/menu_attrib\ - ${EXE_DIR}/menu_item_data\ - ${EXE_DIR}/menu_multi_column \ - ${EXE_DIR}/menu_scroll \ - ${EXE_DIR}/menu_simple \ - ${EXE_DIR}/menu_toggle \ - ${EXE_DIR}/menu_userptr \ - ${EXE_DIR}/menu_win - -${EXE_DIR}/%: %.o - ${CC} -o $@ $< ${LIBS} - -%.o: ${SRC_DIR}/%.c - ${CC} -o $@ -c $< - -all: ${EXES} - - -clean: - @rm -f ${EXES} diff --git a/curses-practice/menus/README b/curses-practice/menus/README deleted file mode 100644 index 211bfa3..0000000 --- a/curses-practice/menus/README +++ /dev/null @@ -1,13 +0,0 @@ -Description of files --------------------- - menus - | - |----> menu_attrib.c -- Usage of menu attributes - |----> menu_item_data.c -- Usage of item_name() etc.. functions - |----> menu_multi_column.c -- Creates multi columnar menus - |----> menu_scroll.c -- Demonstrates scrolling capability of menus - |----> menu_simple.c -- A simple menu accessed by arrow keys - |----> menu_toggle.c -- Creates multi valued menus and explains - | -- REQ_TOGGLE_ITEM - |----> menu_userptr.c -- Usage of user pointer - |----> menu_win.c -- Demo of windows associated with menus diff --git a/curses-practice/menus/menu_attrib.c b/curses-practice/menus/menu_attrib.c deleted file mode 100644 index 56fad90..0000000 --- a/curses-practice/menus/menu_attrib.c +++ /dev/null @@ -1,80 +0,0 @@ -#include - -#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) -#define CTRLD 4 - -char *choices[] = { - "Choice 1", - "Choice 2", - "Choice 3", - "Choice 4", - "Choice 5", - "Choice 6", - "Choice 7", - "Exit", - }; - -int main() -{ ITEM **my_items; - int c; - MENU *my_menu; - int n_choices, i; - ITEM *cur_item; - - /* Initialize curses */ - initscr(); - start_color(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - init_pair(1, COLOR_RED, COLOR_BLACK); - init_pair(2, COLOR_GREEN, COLOR_BLACK); - init_pair(3, COLOR_MAGENTA, COLOR_BLACK); - - /* Initialize items */ - n_choices = ARRAY_SIZE(choices); - my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *)); - for(i = 0; i < n_choices; ++i) - my_items[i] = new_item(choices[i], choices[i]); - my_items[n_choices] = (ITEM *)NULL; - item_opts_off(my_items[3], O_SELECTABLE); - item_opts_off(my_items[6], O_SELECTABLE); - - /* Create menu */ - my_menu = new_menu((ITEM **)my_items); - - /* Set fore ground and back ground of the menu */ - set_menu_fore(my_menu, COLOR_PAIR(1) | A_REVERSE); - set_menu_back(my_menu, COLOR_PAIR(2)); - set_menu_grey(my_menu, COLOR_PAIR(3)); - - /* Post the menu */ - mvprintw(LINES - 3, 0, "Press to see the option selected"); - mvprintw(LINES - 2, 0, "Up and Down arrow keys to naviage (F1 to Exit)"); - post_menu(my_menu); - refresh(); - - while((c = getch()) != KEY_F(1)) - { switch(c) - { case KEY_DOWN: - menu_driver(my_menu, REQ_DOWN_ITEM); - break; - case KEY_UP: - menu_driver(my_menu, REQ_UP_ITEM); - break; - case 10: /* Enter */ - move(20, 0); - clrtoeol(); - mvprintw(20, 0, "Item selected is : %s", - item_name(current_item(my_menu))); - pos_menu_cursor(my_menu); - break; - } - } - unpost_menu(my_menu); - for(i = 0; i < n_choices; ++i) - free_item(my_items[i]); - free_menu(my_menu); - endwin(); -} - diff --git a/curses-practice/menus/menu_item_data.c b/curses-practice/menus/menu_item_data.c deleted file mode 100644 index d33998e..0000000 --- a/curses-practice/menus/menu_item_data.c +++ /dev/null @@ -1,66 +0,0 @@ -#include -#include - -#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) -#define CTRLD 4 - -char *choices[] = { - "Choice 1", - "Choice 2", - "Choice 3", - "Choice 4", - "Exit", - }; - -int main() -{ ITEM **my_items; - int c; - MENU *my_menu; - int n_choices, i; - ITEM *cur_item; - - - initscr(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - - n_choices = ARRAY_SIZE(choices); - my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *)); - - for(i = 0; i < n_choices; ++i) - my_items[i] = new_item(choices[i], choices[i]); - my_items[n_choices] = (ITEM *)NULL; - - my_menu = new_menu((ITEM **)my_items); - post_menu(my_menu); - refresh(); - - while((c = getch()) != KEY_F(1)) - { switch(c) - { case KEY_DOWN: - menu_driver(my_menu, REQ_DOWN_ITEM); - break; - case KEY_UP: - menu_driver(my_menu, REQ_UP_ITEM); - break; - case 10: /* Enter */ - cur_item = current_item(my_menu); - move(LINES - 2, 0); - clrtoeol(); - mvprintw(LINES - 2, 0, "You have chosen %d item with name %s and description %s", - item_index(cur_item) + 1, item_name(cur_item), - item_description(cur_item)); - - refresh(); - pos_menu_cursor(my_menu); - break; - } - } - - free_item(my_items[0]); - free_item(my_items[1]); - free_menu(my_menu); - endwin(); -} - diff --git a/curses-practice/menus/menu_multi_column.c b/curses-practice/menus/menu_multi_column.c deleted file mode 100644 index 1fa6e02..0000000 --- a/curses-practice/menus/menu_multi_column.c +++ /dev/null @@ -1,97 +0,0 @@ -#include -#include - -#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) -#define CTRLD 4 - -char *choices[] = { - "Choice 1", "Choice 2", "Choice 3", "Choice 4", "Choice 5", - "Choice 6", "Choice 7", "Choice 8", "Choice 9", "Choice 10", - "Choice 11", "Choice 12", "Choice 13", "Choice 14", "Choice 15", - "Choice 16", "Choice 17", "Choice 18", "Choice 19", "Choice 20", - "Exit", - (char *)NULL, - }; - -int main() -{ ITEM **my_items; - int c; - MENU *my_menu; - WINDOW *my_menu_win; - int n_choices, i; - - /* Initialize curses */ - initscr(); - start_color(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - init_pair(1, COLOR_RED, COLOR_BLACK); - init_pair(2, COLOR_CYAN, COLOR_BLACK); - - /* Create items */ - n_choices = ARRAY_SIZE(choices); - my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *)); - for(i = 0; i < n_choices; ++i) - my_items[i] = new_item(choices[i], choices[i]); - - /* Crate menu */ - my_menu = new_menu((ITEM **)my_items); - - /* Set menu option not to show the description */ - menu_opts_off(my_menu, O_SHOWDESC); - - /* Create the window to be associated with the menu */ - my_menu_win = newwin(10, 70, 4, 4); - keypad(my_menu_win, TRUE); - - /* Set main window and sub window */ - set_menu_win(my_menu, my_menu_win); - set_menu_sub(my_menu, derwin(my_menu_win, 6, 68, 3, 1)); - set_menu_format(my_menu, 5, 3); - set_menu_mark(my_menu, " * "); - - /* Print a border around the main window and print a title */ - box(my_menu_win, 0, 0); - - attron(COLOR_PAIR(2)); - mvprintw(LINES - 3, 0, "Use PageUp and PageDown to scroll"); - mvprintw(LINES - 2, 0, "Use Arrow Keys to navigate (F1 to Exit)"); - attroff(COLOR_PAIR(2)); - refresh(); - - /* Post the menu */ - post_menu(my_menu); - wrefresh(my_menu_win); - - while((c = wgetch(my_menu_win)) != KEY_F(1)) - { switch(c) - { case KEY_DOWN: - menu_driver(my_menu, REQ_DOWN_ITEM); - break; - case KEY_UP: - menu_driver(my_menu, REQ_UP_ITEM); - break; - case KEY_LEFT: - menu_driver(my_menu, REQ_LEFT_ITEM); - break; - case KEY_RIGHT: - menu_driver(my_menu, REQ_RIGHT_ITEM); - break; - case KEY_NPAGE: - menu_driver(my_menu, REQ_SCR_DPAGE); - break; - case KEY_PPAGE: - menu_driver(my_menu, REQ_SCR_UPAGE); - break; - } - wrefresh(my_menu_win); - } - - /* Unpost and free all the memory taken up */ - unpost_menu(my_menu); - free_menu(my_menu); - for(i = 0; i < n_choices; ++i) - free_item(my_items[i]); - endwin(); -} diff --git a/curses-practice/menus/menu_scroll.c b/curses-practice/menus/menu_scroll.c deleted file mode 100644 index 40618f2..0000000 --- a/curses-practice/menus/menu_scroll.c +++ /dev/null @@ -1,124 +0,0 @@ -#include -#include - -#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) -#define CTRLD 4 - -char *choices[] = { - "Choice 1", - "Choice 2", - "Choice 3", - "Choice 4", - "Choice 5", - "Choice 6", - "Choice 7", - "Choice 8", - "Choice 9", - "Choice 10", - "Exit", - (char *)NULL, - }; -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color); - -int main() -{ ITEM **my_items; - int c; - MENU *my_menu; - WINDOW *my_menu_win; - int n_choices, i; - - /* Initialize curses */ - initscr(); - start_color(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - init_pair(1, COLOR_RED, COLOR_BLACK); - init_pair(2, COLOR_CYAN, COLOR_BLACK); - - /* Create items */ - n_choices = ARRAY_SIZE(choices); - my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *)); - for(i = 0; i < n_choices; ++i) - my_items[i] = new_item(choices[i], choices[i]); - - /* Crate menu */ - my_menu = new_menu((ITEM **)my_items); - - /* Create the window to be associated with the menu */ - my_menu_win = newwin(10, 40, 4, 4); - keypad(my_menu_win, TRUE); - - /* Set main window and sub window */ - set_menu_win(my_menu, my_menu_win); - set_menu_sub(my_menu, derwin(my_menu_win, 6, 38, 3, 1)); - set_menu_format(my_menu, 5, 1); - - /* Set menu mark to the string " * " */ - set_menu_mark(my_menu, " * "); - - /* Print a border around the main window and print a title */ - box(my_menu_win, 0, 0); - print_in_middle(my_menu_win, 1, 0, 40, "My Menu", COLOR_PAIR(1)); - mvwaddch(my_menu_win, 2, 0, ACS_LTEE); - mvwhline(my_menu_win, 2, 1, ACS_HLINE, 38); - mvwaddch(my_menu_win, 2, 39, ACS_RTEE); - - /* Post the menu */ - post_menu(my_menu); - wrefresh(my_menu_win); - - attron(COLOR_PAIR(2)); - mvprintw(LINES - 2, 0, "Use PageUp and PageDown to scoll down or up a page of items"); - mvprintw(LINES - 1, 0, "Arrow Keys to navigate (F1 to Exit)"); - attroff(COLOR_PAIR(2)); - refresh(); - - while((c = wgetch(my_menu_win)) != KEY_F(1)) - { switch(c) - { case KEY_DOWN: - menu_driver(my_menu, REQ_DOWN_ITEM); - break; - case KEY_UP: - menu_driver(my_menu, REQ_UP_ITEM); - break; - case KEY_NPAGE: - menu_driver(my_menu, REQ_SCR_DPAGE); - break; - case KEY_PPAGE: - menu_driver(my_menu, REQ_SCR_UPAGE); - break; - } - wrefresh(my_menu_win); - } - - /* Unpost and free all the memory taken up */ - unpost_menu(my_menu); - free_menu(my_menu); - for(i = 0; i < n_choices; ++i) - free_item(my_items[i]); - endwin(); -} - -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color) -{ int length, x, y; - float temp; - - if(win == NULL) - win = stdscr; - getyx(win, y, x); - if(startx != 0) - x = startx; - if(starty != 0) - y = starty; - if(width == 0) - width = 80; - - length = strlen(string); - temp = (width - length)/ 2; - x = startx + (int)temp; - wattron(win, color); - mvwprintw(win, y, x, "%s", string); - wattroff(win, color); - refresh(); -} diff --git a/curses-practice/menus/menu_simple.c b/curses-practice/menus/menu_simple.c deleted file mode 100644 index 086fdf7..0000000 --- a/curses-practice/menus/menu_simple.c +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include - -#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) -#define CTRLD 4 - -char *choices[] = { - "Choice 1", - "Choice 2", - "Choice 3", - "Choice 4", - "Exit", - }; - -int main() -{ ITEM **my_items; - int c; - MENU *my_menu; - int n_choices, i; - ITEM *cur_item; - - - initscr(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - - n_choices = ARRAY_SIZE(choices); - my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *)); - - for(i = 0; i < n_choices; ++i) - my_items[i] = new_item(choices[i], choices[i]); - my_items[n_choices] = (ITEM *)NULL; - - my_menu = new_menu((ITEM **)my_items); - mvprintw(LINES - 2, 0, "F1 to Exit"); - post_menu(my_menu); - refresh(); - - while((c = getch()) != KEY_F(1)) - { switch(c) - { case KEY_DOWN: - menu_driver(my_menu, REQ_DOWN_ITEM); - break; - case KEY_UP: - menu_driver(my_menu, REQ_UP_ITEM); - break; - } - } - - free_item(my_items[0]); - free_item(my_items[1]); - free_menu(my_menu); - endwin(); -} - diff --git a/curses-practice/menus/menu_toggle.c b/curses-practice/menus/menu_toggle.c deleted file mode 100644 index 60a052f..0000000 --- a/curses-practice/menus/menu_toggle.c +++ /dev/null @@ -1,84 +0,0 @@ -#include -#include - -#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) -#define CTRLD 4 - -char *choices[] = { - "Choice 1", - "Choice 2", - "Choice 3", - "Choice 4", - "Choice 5", - "Choice 6", - "Choice 7", - "Exit", - }; - -int main() -{ ITEM **my_items; - int c; - MENU *my_menu; - int n_choices, i; - ITEM *cur_item; - - /* Initialize curses */ - initscr(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - - /* Initialize items */ - n_choices = ARRAY_SIZE(choices); - my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *)); - for(i = 0; i < n_choices; ++i) - my_items[i] = new_item(choices[i], choices[i]); - my_items[n_choices] = (ITEM *)NULL; - - my_menu = new_menu((ITEM **)my_items); - - /* Make the menu multi valued */ - menu_opts_off(my_menu, O_ONEVALUE); - - mvprintw(LINES - 3, 0, "Use to select or unselect an item."); - mvprintw(LINES - 2, 0, " to see presently selected items(F1 to Exit)"); - post_menu(my_menu); - refresh(); - - while((c = getch()) != KEY_F(1)) - { switch(c) - { case KEY_DOWN: - menu_driver(my_menu, REQ_DOWN_ITEM); - break; - case KEY_UP: - menu_driver(my_menu, REQ_UP_ITEM); - break; - case ' ': - menu_driver(my_menu, REQ_TOGGLE_ITEM); - break; - case 10: /* Enter */ - { char temp[200]; - ITEM **items; - - items = menu_items(my_menu); - temp[0] = '\0'; - for(i = 0; i < item_count(my_menu); ++i) - if(item_value(items[i]) == TRUE) - { strcat(temp, item_name(items[i])); - strcat(temp, " "); - } - move(20, 0); - clrtoeol(); - mvprintw(20, 0, temp); - refresh(); - } - break; - } - } - - free_item(my_items[0]); - free_item(my_items[1]); - free_menu(my_menu); - endwin(); -} - diff --git a/curses-practice/menus/menu_userptr.c b/curses-practice/menus/menu_userptr.c deleted file mode 100644 index d2e02d4..0000000 --- a/curses-practice/menus/menu_userptr.c +++ /dev/null @@ -1,87 +0,0 @@ -#include -#include - -#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) -#define CTRLD 4 - -char *choices[] = { - "Choice 1", - "Choice 2", - "Choice 3", - "Choice 4", - "Choice 5", - "Choice 6", - "Choice 7", - "Exit", - }; -void func(char *name); - -int main() -{ ITEM **my_items; - int c; - MENU *my_menu; - int n_choices, i; - ITEM *cur_item; - - /* Initialize curses */ - initscr(); - start_color(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - init_pair(1, COLOR_RED, COLOR_BLACK); - init_pair(2, COLOR_GREEN, COLOR_BLACK); - init_pair(3, COLOR_MAGENTA, COLOR_BLACK); - - /* Initialize items */ - n_choices = ARRAY_SIZE(choices); - my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *)); - for(i = 0; i < n_choices; ++i) - { my_items[i] = new_item(choices[i], choices[i]); - /* Set the user pointer */ - set_item_userptr(my_items[i], func); - } - my_items[n_choices] = (ITEM *)NULL; - - /* Create menu */ - my_menu = new_menu((ITEM **)my_items); - - /* Post the menu */ - mvprintw(LINES - 3, 0, "Press to see the option selected"); - mvprintw(LINES - 2, 0, "Up and Down arrow keys to naviage (F1 to Exit)"); - post_menu(my_menu); - refresh(); - - while((c = getch()) != KEY_F(1)) - { switch(c) - { case KEY_DOWN: - menu_driver(my_menu, REQ_DOWN_ITEM); - break; - case KEY_UP: - menu_driver(my_menu, REQ_UP_ITEM); - break; - case 10: /* Enter */ - { ITEM *cur; - void (*p)(char *); - - cur = current_item(my_menu); - p = item_userptr(cur); - p((char *)item_name(cur)); - pos_menu_cursor(my_menu); - break; - } - break; - } - } - unpost_menu(my_menu); - for(i = 0; i < n_choices; ++i) - free_item(my_items[i]); - free_menu(my_menu); - endwin(); -} - -void func(char *name) -{ move(20, 0); - clrtoeol(); - mvprintw(20, 0, "Item selected is : %s", name); -} diff --git a/curses-practice/menus/menu_win.c b/curses-practice/menus/menu_win.c deleted file mode 100644 index c3387ed..0000000 --- a/curses-practice/menus/menu_win.c +++ /dev/null @@ -1,105 +0,0 @@ -#include - -#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) -#define CTRLD 4 - -char *choices[] = { - "Choice 1", - "Choice 2", - "Choice 3", - "Choice 4", - "Exit", - (char *)NULL, - }; -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color); - -int main() -{ ITEM **my_items; - int c; - MENU *my_menu; - WINDOW *my_menu_win; - int n_choices, i; - - /* Initialize curses */ - initscr(); - start_color(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - init_pair(1, COLOR_RED, COLOR_BLACK); - - /* Create items */ - n_choices = ARRAY_SIZE(choices); - my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *)); - for(i = 0; i < n_choices; ++i) - my_items[i] = new_item(choices[i], choices[i]); - - /* Crate menu */ - my_menu = new_menu((ITEM **)my_items); - - /* Create the window to be associated with the menu */ - my_menu_win = newwin(10, 40, 4, 4); - keypad(my_menu_win, TRUE); - - /* Set main window and sub window */ - set_menu_win(my_menu, my_menu_win); - set_menu_sub(my_menu, derwin(my_menu_win, 6, 38, 3, 1)); - - /* Set menu mark to the string " * " */ - set_menu_mark(my_menu, " * "); - - /* Print a border around the main window and print a title */ - box(my_menu_win, 0, 0); - print_in_middle(my_menu_win, 1, 0, 40, "My Menu", COLOR_PAIR(1)); - mvwaddch(my_menu_win, 2, 0, ACS_LTEE); - mvwhline(my_menu_win, 2, 1, ACS_HLINE, 38); - mvwaddch(my_menu_win, 2, 39, ACS_RTEE); - mvprintw(LINES - 2, 0, "F1 to exit"); - refresh(); - - /* Post the menu */ - post_menu(my_menu); - wrefresh(my_menu_win); - - while((c = wgetch(my_menu_win)) != KEY_F(1)) - { switch(c) - { case KEY_DOWN: - menu_driver(my_menu, REQ_DOWN_ITEM); - break; - case KEY_UP: - menu_driver(my_menu, REQ_UP_ITEM); - break; - } - wrefresh(my_menu_win); - } - - /* Unpost and free all the memory taken up */ - unpost_menu(my_menu); - free_menu(my_menu); - for(i = 0; i < n_choices; ++i) - free_item(my_items[i]); - endwin(); -} - -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color) -{ int length, x, y; - float temp; - - if(win == NULL) - win = stdscr; - getyx(win, y, x); - if(startx != 0) - x = startx; - if(starty != 0) - y = starty; - if(width == 0) - width = 80; - - length = strlen(string); - temp = (width - length)/ 2; - x = startx + (int)temp; - wattron(win, color); - mvwprintw(win, y, x, "%s", string); - wattroff(win, color); - refresh(); -} diff --git a/curses-practice/panels/Makefile b/curses-practice/panels/Makefile deleted file mode 100644 index 242df7c..0000000 --- a/curses-practice/panels/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -# Makefile for JustForFun Files - -# A few variables - -CC=gcc -LIBS=-lpanel -lncurses - -SRC_DIR=. -EXE_DIR=../demo/exe - -EXES = \ - ${EXE_DIR}/panel_browse \ - ${EXE_DIR}/panel_hide \ - ${EXE_DIR}/panel_resize \ - ${EXE_DIR}/panel_simple - -${EXE_DIR}/%: %.o - ${CC} -o $@ $< ${LIBS} - -%.o: ${SRC_DIR}/%.c - ${CC} -o $@ -c $< - -all: ${EXES} - - -clean: - @rm -f ${EXES} diff --git a/curses-practice/panels/README b/curses-practice/panels/README deleted file mode 100644 index ed34678..0000000 --- a/curses-practice/panels/README +++ /dev/null @@ -1,8 +0,0 @@ -Description of files --------------------- - panels - | - |----> panel_browse.c -- Panel browsing through tab. Usage of user pointer - |----> panel_hide.c -- Hiding and Un hiding of panels - |----> panel_resize.c -- Moving and resizing of panels - |----> panel_simple.c -- A simple panel example diff --git a/curses-practice/panels/panel_browse.c b/curses-practice/panels/panel_browse.c deleted file mode 100644 index 013c066..0000000 --- a/curses-practice/panels/panel_browse.c +++ /dev/null @@ -1,117 +0,0 @@ -#include - -#define NLINES 10 -#define NCOLS 40 - -void init_wins(WINDOW **wins, int n); -void win_show(WINDOW *win, char *label, int label_color); -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color); - -int main() -{ WINDOW *my_wins[3]; - PANEL *my_panels[3]; - PANEL *top; - int ch; - - /* Initialize curses */ - initscr(); - start_color(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - - /* Initialize all the colors */ - init_pair(1, COLOR_RED, COLOR_BLACK); - init_pair(2, COLOR_GREEN, COLOR_BLACK); - init_pair(3, COLOR_BLUE, COLOR_BLACK); - init_pair(4, COLOR_CYAN, COLOR_BLACK); - - init_wins(my_wins, 3); - - /* Attach a panel to each window */ /* Order is bottom up */ - my_panels[0] = new_panel(my_wins[0]); /* Push 0, order: stdscr-0 */ - my_panels[1] = new_panel(my_wins[1]); /* Push 1, order: stdscr-0-1 */ - my_panels[2] = new_panel(my_wins[2]); /* Push 2, order: stdscr-0-1-2 */ - - /* Set up the user pointers to the next panel */ - set_panel_userptr(my_panels[0], my_panels[1]); - set_panel_userptr(my_panels[1], my_panels[2]); - set_panel_userptr(my_panels[2], my_panels[0]); - - /* Update the stacking order. 2nd panel will be on top */ - update_panels(); - - /* Show it on the screen */ - attron(COLOR_PAIR(4)); - mvprintw(LINES - 2, 0, "Use tab to browse through the windows (F1 to Exit)"); - attroff(COLOR_PAIR(4)); - doupdate(); - - top = my_panels[2]; - while((ch = getch()) != KEY_F(1)) - { switch(ch) - { case 9: - top = (PANEL *)panel_userptr(top); - top_panel(top); - break; - } - update_panels(); - doupdate(); - } - endwin(); - return 0; -} - -/* Put all the windows */ -void init_wins(WINDOW **wins, int n) -{ int x, y, i; - char label[80]; - - y = 2; - x = 10; - for(i = 0; i < n; ++i) - { wins[i] = newwin(NLINES, NCOLS, y, x); - sprintf(label, "Window Number %d", i + 1); - win_show(wins[i], label, i + 1); - y += 3; - x += 7; - } -} - -/* Show the window with a border and a label */ -void win_show(WINDOW *win, char *label, int label_color) -{ int startx, starty, height, width; - - getbegyx(win, starty, startx); - getmaxyx(win, height, width); - - box(win, 0, 0); - mvwaddch(win, 2, 0, ACS_LTEE); - mvwhline(win, 2, 1, ACS_HLINE, width - 2); - mvwaddch(win, 2, width - 1, ACS_RTEE); - - print_in_middle(win, 1, 0, width, label, COLOR_PAIR(label_color)); -} - -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color) -{ int length, x, y; - float temp; - - if(win == NULL) - win = stdscr; - getyx(win, y, x); - if(startx != 0) - x = startx; - if(starty != 0) - y = starty; - if(width == 0) - width = 80; - - length = strlen(string); - temp = (width - length)/ 2; - x = startx + (int)temp; - wattron(win, color); - mvwprintw(win, y, x, "%s", string); - wattroff(win, color); - refresh(); -} diff --git a/curses-practice/panels/panel_hide.c b/curses-practice/panels/panel_hide.c deleted file mode 100644 index 457199c..0000000 --- a/curses-practice/panels/panel_hide.c +++ /dev/null @@ -1,156 +0,0 @@ -#include - -typedef struct _PANEL_DATA { - int hide; /* TRUE if panel is hidden */ -}PANEL_DATA; - -#define NLINES 10 -#define NCOLS 40 - -void init_wins(WINDOW **wins, int n); -void win_show(WINDOW *win, char *label, int label_color); -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color); - -int main() -{ WINDOW *my_wins[3]; - PANEL *my_panels[3]; - PANEL_DATA panel_datas[3]; - PANEL_DATA *temp; - int ch; - - /* Initialize curses */ - initscr(); - start_color(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - - /* Initialize all the colors */ - init_pair(1, COLOR_RED, COLOR_BLACK); - init_pair(2, COLOR_GREEN, COLOR_BLACK); - init_pair(3, COLOR_BLUE, COLOR_BLACK); - init_pair(4, COLOR_CYAN, COLOR_BLACK); - - init_wins(my_wins, 3); - - /* Attach a panel to each window */ /* Order is bottom up */ - my_panels[0] = new_panel(my_wins[0]); /* Push 0, order: stdscr-0 */ - my_panels[1] = new_panel(my_wins[1]); /* Push 1, order: stdscr-0-1 */ - my_panels[2] = new_panel(my_wins[2]); /* Push 2, order: stdscr-0-1-2 */ - - /* Initialize panel datas saying that nothing is hidden */ - panel_datas[0].hide = FALSE; - panel_datas[1].hide = FALSE; - panel_datas[2].hide = FALSE; - - set_panel_userptr(my_panels[0], &panel_datas[0]); - set_panel_userptr(my_panels[1], &panel_datas[1]); - set_panel_userptr(my_panels[2], &panel_datas[2]); - - /* Update the stacking order. 2nd panel will be on top */ - update_panels(); - - /* Show it on the screen */ - attron(COLOR_PAIR(4)); - mvprintw(LINES - 3, 0, "Show or Hide a window with 'a'(first window) 'b'(Second Window) 'c'(Third Window)"); - mvprintw(LINES - 2, 0, "F1 to Exit"); - - attroff(COLOR_PAIR(4)); - doupdate(); - - while((ch = getch()) != KEY_F(1)) - { switch(ch) - { case 'a': - temp = (PANEL_DATA *)panel_userptr(my_panels[0]); - if(temp->hide == FALSE) - { hide_panel(my_panels[0]); - temp->hide = TRUE; - } - else - { show_panel(my_panels[0]); - temp->hide = FALSE; - } - break; - case 'b': - temp = (PANEL_DATA *)panel_userptr(my_panels[1]); - if(temp->hide == FALSE) - { hide_panel(my_panels[1]); - temp->hide = TRUE; - } - else - { show_panel(my_panels[1]); - temp->hide = FALSE; - } - break; - case 'c': - temp = (PANEL_DATA *)panel_userptr(my_panels[2]); - if(temp->hide == FALSE) - { hide_panel(my_panels[2]); - temp->hide = TRUE; - } - else - { show_panel(my_panels[2]); - temp->hide = FALSE; - } - break; - } - update_panels(); - doupdate(); - } - endwin(); - return 0; -} - -/* Put all the windows */ -void init_wins(WINDOW **wins, int n) -{ int x, y, i; - char label[80]; - - y = 2; - x = 10; - for(i = 0; i < n; ++i) - { wins[i] = newwin(NLINES, NCOLS, y, x); - sprintf(label, "Window Number %d", i + 1); - win_show(wins[i], label, i + 1); - y += 3; - x += 7; - } -} - -/* Show the window with a border and a label */ -void win_show(WINDOW *win, char *label, int label_color) -{ int startx, starty, height, width; - - getbegyx(win, starty, startx); - getmaxyx(win, height, width); - - box(win, 0, 0); - mvwaddch(win, 2, 0, ACS_LTEE); - mvwhline(win, 2, 1, ACS_HLINE, width - 2); - mvwaddch(win, 2, width - 1, ACS_RTEE); - - print_in_middle(win, 1, 0, width, label, COLOR_PAIR(label_color)); -} - -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color) -{ int length, x, y; - float temp; - - if(win == NULL) - win = stdscr; - getyx(win, y, x); - if(startx != 0) - x = startx; - if(starty != 0) - y = starty; - if(width == 0) - width = 80; - - length = strlen(string); - temp = (width - length)/ 2; - x = startx + (int)temp; - wattron(win, color); - mvwprintw(win, y, x, "%s", string); - wattroff(win, color); - refresh(); -} diff --git a/curses-practice/panels/panel_resize.c b/curses-practice/panels/panel_resize.c deleted file mode 100644 index e77ba0d..0000000 --- a/curses-practice/panels/panel_resize.c +++ /dev/null @@ -1,234 +0,0 @@ -#include - -typedef struct _PANEL_DATA { - int x, y, w, h; - char label[80]; - int label_color; - PANEL *next; -}PANEL_DATA; - -#define NLINES 10 -#define NCOLS 40 - -void init_wins(WINDOW **wins, int n); -void win_show(WINDOW *win, char *label, int label_color); -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color); -void set_user_ptrs(PANEL **panels, int n); - -int main() -{ WINDOW *my_wins[3]; - PANEL *my_panels[3]; - PANEL_DATA *top; - PANEL *stack_top; - WINDOW *temp_win, *old_win; - int ch; - int newx, newy, neww, newh; - int size = FALSE, move = FALSE; - - /* Initialize curses */ - initscr(); - start_color(); - cbreak(); - noecho(); - keypad(stdscr, TRUE); - - /* Initialize all the colors */ - init_pair(1, COLOR_RED, COLOR_BLACK); - init_pair(2, COLOR_GREEN, COLOR_BLACK); - init_pair(3, COLOR_BLUE, COLOR_BLACK); - init_pair(4, COLOR_CYAN, COLOR_BLACK); - - init_wins(my_wins, 3); - - /* Attach a panel to each window */ /* Order is bottom up */ - my_panels[0] = new_panel(my_wins[0]); /* Push 0, order: stdscr-0 */ - my_panels[1] = new_panel(my_wins[1]); /* Push 1, order: stdscr-0-1 */ - my_panels[2] = new_panel(my_wins[2]); /* Push 2, order: stdscr-0-1-2 */ - - set_user_ptrs(my_panels, 3); - /* Update the stacking order. 2nd panel will be on top */ - update_panels(); - - /* Show it on the screen */ - attron(COLOR_PAIR(4)); - mvprintw(LINES - 3, 0, "Use 'm' for moving, 'r' for resizing"); - mvprintw(LINES - 2, 0, "Use tab to browse through the windows (F1 to Exit)"); - attroff(COLOR_PAIR(4)); - doupdate(); - - stack_top = my_panels[2]; - top = (PANEL_DATA *)panel_userptr(stack_top); - newx = top->x; - newy = top->y; - neww = top->w; - newh = top->h; - while((ch = getch()) != KEY_F(1)) - { switch(ch) - { case 9: /* Tab */ - top = (PANEL_DATA *)panel_userptr(stack_top); - top_panel(top->next); - stack_top = top->next; - top = (PANEL_DATA *)panel_userptr(stack_top); - newx = top->x; - newy = top->y; - neww = top->w; - newh = top->h; - break; - case 'r': /* Re-Size*/ - size = TRUE; - attron(COLOR_PAIR(4)); - mvprintw(LINES - 4, 0, "Entered Resizing :Use Arrow Keys to resize and press to end resizing"); - refresh(); - attroff(COLOR_PAIR(4)); - break; - case 'm': /* Move */ - attron(COLOR_PAIR(4)); - mvprintw(LINES - 4, 0, "Entered Moving: Use Arrow Keys to Move and press to end moving"); - refresh(); - attroff(COLOR_PAIR(4)); - move = TRUE; - break; - case KEY_LEFT: - if(size == TRUE) - { --newx; - ++neww; - } - if(move == TRUE) - --newx; - break; - case KEY_RIGHT: - if(size == TRUE) - { ++newx; - --neww; - } - if(move == TRUE) - ++newx; - break; - case KEY_UP: - if(size == TRUE) - { --newy; - ++newh; - } - if(move == TRUE) - --newy; - break; - case KEY_DOWN: - if(size == TRUE) - { ++newy; - --newh; - } - if(move == TRUE) - ++newy; - break; - case 10: /* Enter */ - move(LINES - 4, 0); - clrtoeol(); - refresh(); - if(size == TRUE) - { old_win = panel_window(stack_top); - temp_win = newwin(newh, neww, newy, newx); - replace_panel(stack_top, temp_win); - win_show(temp_win, top->label, top->label_color); - delwin(old_win); - size = FALSE; - } - if(move == TRUE) - { move_panel(stack_top, newy, newx); - move = FALSE; - } - break; - - } - attron(COLOR_PAIR(4)); - mvprintw(LINES - 3, 0, "Use 'm' for moving, 'r' for resizing"); - mvprintw(LINES - 2, 0, "Use tab to browse through the windows (F1 to Exit)"); - attroff(COLOR_PAIR(4)); - refresh(); - update_panels(); - doupdate(); - } - endwin(); - return 0; -} - -/* Put all the windows */ -void init_wins(WINDOW **wins, int n) -{ int x, y, i; - char label[80]; - - y = 2; - x = 10; - for(i = 0; i < n; ++i) - { wins[i] = newwin(NLINES, NCOLS, y, x); - sprintf(label, "Window Number %d", i + 1); - win_show(wins[i], label, i + 1); - y += 3; - x += 7; - } -} - -/* Set the PANEL_DATA structures for individual panels */ -void set_user_ptrs(PANEL **panels, int n) -{ PANEL_DATA *ptrs; - WINDOW *win; - int x, y, w, h, i; - char temp[80]; - - ptrs = (PANEL_DATA *)calloc(n, sizeof(PANEL_DATA)); - - for(i = 0;i < n; ++i) - { win = panel_window(panels[i]); - getbegyx(win, y, x); - getmaxyx(win, h, w); - ptrs[i].x = x; - ptrs[i].y = y; - ptrs[i].w = w; - ptrs[i].h = h; - sprintf(temp, "Window Number %d", i + 1); - strcpy(ptrs[i].label, temp); - ptrs[i].label_color = i + 1; - if(i + 1 == n) - ptrs[i].next = panels[0]; - else - ptrs[i].next = panels[i + 1]; - set_panel_userptr(panels[i], &ptrs[i]); - } -} - -/* Show the window with a border and a label */ -void win_show(WINDOW *win, char *label, int label_color) -{ int startx, starty, height, width; - - getbegyx(win, starty, startx); - getmaxyx(win, height, width); - - box(win, 0, 0); - mvwaddch(win, 2, 0, ACS_LTEE); - mvwhline(win, 2, 1, ACS_HLINE, width - 2); - mvwaddch(win, 2, width - 1, ACS_RTEE); - - print_in_middle(win, 1, 0, width, label, COLOR_PAIR(label_color)); -} - -void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color) -{ int length, x, y; - float temp; - - if(win == NULL) - win = stdscr; - getyx(win, y, x); - if(startx != 0) - x = startx; - if(starty != 0) - y = starty; - if(width == 0) - width = 80; - - length = strlen(string); - temp = (width - length)/ 2; - x = startx + (int)temp; - wattron(win, color); - mvwprintw(win, y, x, "%s", string); - wattroff(win, color); - refresh(); -} diff --git a/curses-practice/panels/panel_simple.c b/curses-practice/panels/panel_simple.c deleted file mode 100644 index 2ce8c18..0000000 --- a/curses-practice/panels/panel_simple.c +++ /dev/null @@ -1,38 +0,0 @@ -#include - -int main() -{ WINDOW *my_wins[3]; - PANEL *my_panels[3]; - int lines = 10, cols = 40, y = 2, x = 4, i; - - initscr(); - cbreak(); - noecho(); - - /* Create windows for the panels */ - my_wins[0] = newwin(lines, cols, y, x); - my_wins[1] = newwin(lines, cols, y + 1, x + 5); - my_wins[2] = newwin(lines, cols, y + 2, x + 10); - - /* - * Create borders around the windows so that you can see the effect - * of panels - */ - for(i = 0; i < 3; ++i) - box(my_wins[i], 0, 0); - - /* Attach a panel to each window */ /* Order is bottom up */ - my_panels[0] = new_panel(my_wins[0]); /* Push 0, order: stdscr-0 */ - my_panels[1] = new_panel(my_wins[1]); /* Push 1, order: stdscr-0-1 */ - my_panels[2] = new_panel(my_wins[2]); /* Push 2, order: stdscr-0-1-2 */ - - /* Update the stacking order. 2nd panel will be on top */ - update_panels(); - - /* Show it on the screen */ - doupdate(); - - getch(); - endwin(); -} - diff --git a/curses-practice/perl/01.pl b/curses-practice/perl/01.pl deleted file mode 100755 index a4592d7..0000000 --- a/curses-practice/perl/01.pl +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/perl -# -# Copyright (C) 2003 by Virtusa Corporation -# http://www.virtusa.com -# -# Anuradha Ratnaweera -# http://www.linux.lk/~anuradha/ -# - -use Curses; - -initscr(); -printw("Hello world!"); -refresh(); -getch(); -endwin(); - diff --git a/curses-practice/perl/02.pl b/curses-practice/perl/02.pl deleted file mode 100755 index 9862d7e..0000000 --- a/curses-practice/perl/02.pl +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/perl -# -# Copyright (C) 2003 by Virtusa Corporation -# http://www.virtusa.com -# -# Anuradha Ratnaweera -# http://www.linux.lk/~anuradha/ -# - -use Curses; - -initscr(); -raw(); -keypad(1); -noecho(); - -printw("Type any character to see it in bold\n"); -$ch = getch(); - -if ($ch == KEY_F(1)) { - printw("F1 Key pressed"); -} -else { - printw("The pressed key is "); - attron(A_BOLD); - printw($ch); - attroff(A_BOLD); -} - -refresh(); -getch(); -endwin(); - diff --git a/curses-practice/perl/03.pl b/curses-practice/perl/03.pl deleted file mode 100755 index 5ef6c89..0000000 --- a/curses-practice/perl/03.pl +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/perl -# -# Copyright (C) 2003 by Virtusa Corporation -# http://www.virtusa.com -# -# Anuradha Ratnaweera -# http://www.linux.lk/~anuradha/ -# - -# We use addstr() instead of printw() - -use Curses; - -$mesg = "Just a string"; - -initscr(); -getmaxyx($row, $col); -addstr($row / 2, ($col - length($mesg)) / 2, $mesg); -addstr($row - 2, 0, "This screen has $row rows and $col columns\n"); -refresh(); -getch(); -endwin(); - diff --git a/curses-practice/perl/04.pl b/curses-practice/perl/04.pl deleted file mode 100755 index 91cde01..0000000 --- a/curses-practice/perl/04.pl +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/perl -# -# Copyright (C) 2003 by Virtusa Corporation -# http://www.virtusa.com -# -# Anuradha Ratnaweera -# http://www.linux.lk/~anuradha/ -# - -# We use addstr() instead of printw() - -use Curses; - -$mesg = "Enter a string: "; - -initscr(); -getmaxyx($row, $col); -addstr($row / 2, ($col - length($mesg)) / 2, $mesg); -getstr($str); -addstr($LINES - 2, 0, "You Entered: $str"); -getch(); -endwin(); - diff --git a/curses-practice/perl/05.pl b/curses-practice/perl/05.pl deleted file mode 100755 index dc61845..0000000 --- a/curses-practice/perl/05.pl +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/perl -# -# Copyright (C) 2003 by Virtusa Corporation -# http://www.virtusa.com -# -# Anuradha Ratnaweera -# http://www.linux.lk/~anuradha/ -# - -# We first read all the input into an array and join -# it to a single string with newlines. - -use Curses; - -initscr(); - -@lines = <>; -$lines = join "", @lines; - -while ($lines =~ /\G(.*?)(\/\*.*?\*\/)?/gs) { - addstr($1); - if ($2) { - attron(A_BOLD); - addstr($2); - attroff(A_BOLD); - } -} - -refresh(); -getch(); -endwin(); - diff --git a/curses-practice/perl/06.pl b/curses-practice/perl/06.pl deleted file mode 100755 index ac949c6..0000000 --- a/curses-practice/perl/06.pl +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/perl -# -# Copyright (C) 2003 by Virtusa Corporation -# http://www.virtusa.com -# -# Anuradha Ratnaweera -# http://www.linux.lk/~anuradha/ -# - -use Curses; - -initscr(); -start_color(); - -init_pair(1, COLOR_CYAN, COLOR_BLACK); -printw("A Big string which i didn't care to type fully "); -chgat(0, 0, -1, A_BLINK, 1, NULL); - -refresh(); -getch(); -endwin(); - diff --git a/curses-practice/perl/07.pl b/curses-practice/perl/07.pl deleted file mode 100755 index 06a7549..0000000 --- a/curses-practice/perl/07.pl +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/perl -# -# Copyright (C) 2003 by Virtusa Corporation -# http://www.virtusa.com -# -# Anuradha Ratnaweera -# http://www.linux.lk/~anuradha/ -# - -use Curses; - -initscr(); -cbreak(); -keypad(1); - -$height = 3; -$width = 10; -$starty = ($LINES - $height) / 2; -$startx = ($COLS - $width) / 2; -printw("Press F1 to exit"); -refresh(); -$my_win = create_newwin($height, $width, $starty, $startx); - -while (($ch = getch()) != KEY_F(1)) { - if ($ch == KEY_LEFT) { - destroy_win($my_win); - $my_win = create_newwin($height, $width, $starty, --$startx); - } - elsif ($ch == KEY_RIGHT) { - destroy_win($my_win); - $my_win = create_newwin($height, $width, $starty, ++$startx); - } - elsif ($ch == KEY_UP) { - destroy_win($my_win); - $my_win = create_newwin($height, $width, --$starty, $startx); - } - elsif ($ch == KEY_DOWN) { - destroy_win($my_win); - $my_win = create_newwin($height, $width, ++$starty, $startx); - } -} - -endwin(); - -sub create_newwin { - $local_win = newwin(shift, shift, shift, shift); - box($local_win, 0, 0); - refresh($local_win); - return $local_win; -} - -sub destroy_win { - $local_win = shift; - border($local_win, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '); - refresh($local_win); - delwin($local_win); -} - diff --git a/curses-practice/perl/08.pl b/curses-practice/perl/08.pl deleted file mode 100755 index 4eb044f..0000000 --- a/curses-practice/perl/08.pl +++ /dev/null @@ -1,112 +0,0 @@ -#!/usr/bin/perl -# -# Copyright (C) 2003 by Virtusa Corporation -# http://www.virtusa.com -# -# Anuradha Ratnaweera -# http://www.linux.lk/~anuradha/ -# - -# We use %win hash to store window parameters - -use Curses; - -initscr(); -start_color(); -cbreak(); - -keypad(1); -noecho(); -init_pair(1, COLOR_CYAN, COLOR_BLACK); - -%win = (); -init_win_params(\%win); -print_win_params(\%win); - -attron(COLOR_PAIR(1)); -printw("Press F1 to exit"); -refresh(); -attroff(COLOR_PAIR(1)); - -create_box(\%win, 1); - -while (($ch = getch()) != KEY_F(1)) { - if ($ch == KEY_LEFT) { - create_box(\%win, 0); - $win{'startx'}--; - create_box(\%win, 1); - } - elsif ($ch == KEY_RIGHT) { - create_box(\%win, 0); - $win{'startx'}++; - create_box(\%win, 1); - } - elsif ($ch == KEY_UP) { - create_box(\%win, 0); - $win{'starty'}--; - create_box(\%win, 1); - } - elsif ($ch == KEY_DOWN) { - create_box(\%win, 0); - $win{'starty'}++; - create_box(\%win, 1); - } -} - -endwin(); - -sub init_win_params { - $p_win = shift; - - $$p_win{'height'} = 3; - $$p_win{'width'} = 10; - $$p_win{'starty'} = ($LINES - $p_win{'height'}) / 2; - $$p_win{'startx'} = ($COLS - $p_win{'width'}) / 2; - $$p_win{'ls'} = '|'; - $$p_win{'rs'} = '|'; - $$p_win{'ts'} = '-'; - $$p_win{'bs'} = '-'; - $$p_win{'tl'} = '+'; - $$p_win{'tr'} = '+'; - $$p_win{'bl'} = '+'; - $$p_win{'br'} = '+'; -} - -sub print_win_params { - if ($_DEBUG) { - $p_win = shift; - addstr(25, 0, - "$$p_win{startx} $$p_win{starty} $$p_win{width} $$p_win{height}"); - refresh(); - } -} - -sub create_box { - $p_win = shift; - $bool = shift; - - $x = $$p_win{'startx'}; - $y = $$p_win{'starty'}; - $w = $$p_win{'width'}; - $h = $$p_win{'height'}; - - if ($bool) { - addch($y, $x, $$p_win{'tl'}); - addch($y, $x + $w, $$p_win{'tr'}); - addch($y + $h, $x, $$p_win{'bl'}); - addch($y + $h, $x + $w, $$p_win{'br'}); - hline($y, $x + 1, $$p_win{'ts'}, $w - 1); - hline($y + $h, $x + 1, $$p_win{'bs'}, $w - 1); - vline($y + 1, $x, $$p_win{'ls'}, $h - 1); - vline($y + 1, $x + $w, $$p_win{'rs'}, $h - 1); - } - else { - for ($j = $y; $j <= $y + $h; $j++) { - for ($i = $x; $i <= $x + $w; $i++) { - addch($j, $i, ' '); - } - } - } - refresh(); -} - diff --git a/curses-practice/perl/09.pl b/curses-practice/perl/09.pl deleted file mode 100755 index 235fc82..0000000 --- a/curses-practice/perl/09.pl +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/perl -# -# Copyright (C) 2003 by Virtusa Corporation -# http://www.virtusa.com -# -# Anuradha Ratnaweera -# http://www.linux.lk/~anuradha/ -# - -use Curses; - -initscr(); -unless (has_colors()) { - endwin(); - print "Your terminal does not support color\n"; - exit 1; -} -start_color(); -init_pair(1, COLOR_RED, COLOR_BLACK); - -attron(COLOR_PAIR(1)); -print_in_middle(stdscr, $LINES / 2, 0, 0, "Viola !!! In color ..."); -attroff(COLOR_PAIR(1)); -getch(); -endwin(); - -sub print_in_middle { - $win = shift; - $starty = shift; - $startx = shift; - $width = shift; - $string = shift; - - $win = stdscr unless ($win); - - getyx($win, $y, $x); - - $x = $startx if ($startx); - $y = $starty if ($starty); - $width = $COLS unless ($width); - $length = length($string); - $temp = ($width - $length) / 2; - $x = $startx + $temp; - addstr($y, $x, $string); - refresh(); -} - diff --git a/curses-practice/perl/10.pl b/curses-practice/perl/10.pl deleted file mode 100755 index 7353ddb..0000000 --- a/curses-practice/perl/10.pl +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/perl -# -# Copyright (C) 2003 by Virtusa Corporation -# http://www.virtusa.com -# -# Anuradha Ratnaweera -# http://www.linux.lk/~anuradha/ -# - -use Curses; - -$width = 30; -$height = 10; -$startx = 0; -$starty = 0; - -@choices = ( - "Choice 1", - "Choice 2", - "Choice 3", - "Choice 4", - "Exit" -); - -$n_choices = @choices; - -$highlight = 1; -$choice = 0; - -initscr(); -clear(); -noecho(); -cbreak(); -$startx = ($COLS - $width) / 2; -$starty = ($LINES - $height) / 2; - -$menu_win = newwin($height, $width, $starty, $startx); -keypad(1); -keypad($menu_win, 1); -addstr(0, 0, "Use arrow keys to go up and down, Press enter to select a choice"); -refresh(); -print_menu($menu_win, $highlight); - -while (1) { - $c = getch($menu_win); - if ($c == KEY_UP) { - if ($highlight == 1) { - $highlight = $n_choices; - } - else { - $highlight--; - } - } - elsif ($c == KEY_DOWN) { - if ($highlight == $n_choices) { - $highlight = 1; - } - else { - $highlight++; - } - } - elsif ($c == '\n') { - $choice = $highlight; - } - else { - addstr($LINES - 2, 0, "Character pressed is $c"); - refresh(); - } - print_menu($menu_win, $highlight); - last if ($choice); -} - -addstr($LINES - 2, 0, "You chose choice $choice with choice string $choices[$choice-1]"); -clrtoeol(); -refresh(); -endwin(); - -sub print_menu { - $menu_win = shift; - $highlight = shift; - - $x = 2; - $y = 2; - box($menu_win, 0, 0); - for ($i = 0; $i < $n_choices; $i++) { - if ($highlight == $i + 1) { - attron($menu_win, A_REVERSE); - addstr($menu_win, $y, $x, $choices[$i]); - attroff($menu_win, A_REVERSE); - } - else { - addstr($menu_win, $y, $x, $choices[$i]); - } - $y++; - } - refresh($menu_win); -} - diff --git a/curses-practice/perl/COPYING b/curses-practice/perl/COPYING deleted file mode 100644 index 23574ed..0000000 --- a/curses-practice/perl/COPYING +++ /dev/null @@ -1,2 +0,0 @@ -These programmes can be distributed under the same terms as -ncurses (MIT style license). diff --git a/curses-practice/perl/README b/curses-practice/perl/README deleted file mode 100644 index f283923..0000000 --- a/curses-practice/perl/README +++ /dev/null @@ -1,6 +0,0 @@ -The license was changed from GNU/GPL to MIT style license -which is of course compatible with GPL, in order to include -them in the official ncurses-HOWTO. - -Anuradha Ratnaweera (anuradha at gnu org OR gnu.slash.linux at -gmail com OR anuradha at linux lk). diff --git a/java-practice/.gitignore b/java-practice/.gitignore deleted file mode 100644 index 7560428..0000000 --- a/java-practice/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.class -dist diff --git a/java-practice/build.xml b/java-practice/build.xml deleted file mode 100644 index b8aa7f1..0000000 --- a/java-practice/build.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java-practice/foobar.properties b/java-practice/foobar.properties deleted file mode 100644 index 665a380..0000000 --- a/java-practice/foobar.properties +++ /dev/null @@ -1,2 +0,0 @@ -foo.bar = hambones -ham.bones = foobar diff --git a/java-practice/obj/.keep b/java-practice/obj/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/java-practice/src/com/meatballhat/learningjava/CleanPipe.java b/java-practice/src/com/meatballhat/learningjava/CleanPipe.java deleted file mode 100644 index 8fb1f42..0000000 --- a/java-practice/src/com/meatballhat/learningjava/CleanPipe.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.meatballhat.learningjava; - -import java.io.IOException; - - -public final class CleanPipe { - - public static void main(String[] argv) throws IOException { - int c; - while((c = System.in.read()) != -1) { - System.out.write(c); - } - } -} diff --git a/java-practice/src/com/meatballhat/learningjava/HelloSir.java b/java-practice/src/com/meatballhat/learningjava/HelloSir.java deleted file mode 100644 index c93bf4e..0000000 --- a/java-practice/src/com/meatballhat/learningjava/HelloSir.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.meatballhat.learningjava; - - -public class HelloSir { - - public static void main(String[] argv) { - System.out.println("OMG Hi Der"); - } -} diff --git a/java-practice/src/com/meatballhat/learningjava/ShowProps.java b/java-practice/src/com/meatballhat/learningjava/ShowProps.java deleted file mode 100644 index d47e9a8..0000000 --- a/java-practice/src/com/meatballhat/learningjava/ShowProps.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.meatballhat.learningjava; - -import java.io.FileInputStream; -import java.util.Properties; - - -public class ShowProps { - public static String USAGE = "Usage: ShowProps "; - - public static void main(String[] args) - { - try { - - if (args.length >= 1) { - FileInputStream instream = new FileInputStream(args[0]); - Properties props = new Properties(); - props.load(instream); - instream.close(); - props.list(System.out); - - } else { - System.out.println(USAGE); - return; - } - } catch (Exception e) { - System.out.println("OMG FAIL"); - e.printStackTrace(); - } - - } - -} diff --git a/one-time-pad/.gitignore b/one-time-pad/.gitignore deleted file mode 100644 index fab747d..0000000 --- a/one-time-pad/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -*.pyc -.coverage -*.egg-info -build -dist -setup.py -paver-minilib.zip diff --git a/one-time-pad/MANIFEST.in b/one-time-pad/MANIFEST.in deleted file mode 100644 index 305c839..0000000 --- a/one-time-pad/MANIFEST.in +++ /dev/null @@ -1 +0,0 @@ -include *.py *.zip diff --git a/one-time-pad/README b/one-time-pad/README deleted file mode 100644 index 89a723f..0000000 --- a/one-time-pad/README +++ /dev/null @@ -1,3 +0,0 @@ -Sure, they aren't especially practical, but one-time pads are academically interesting :) - -.. vim:filetype=rst diff --git a/one-time-pad/itest_onetimepad.py b/one-time-pad/itest_onetimepad.py deleted file mode 100644 index 45a6180..0000000 --- a/one-time-pad/itest_onetimepad.py +++ /dev/null @@ -1,191 +0,0 @@ -import unittest -import onetimepad as OT - - -class TestMod25(unittest.TestCase): - msg = ('HOWMUCHCHUCKCOULDAWOODCHUCKCHUCKIFA' - 'WOODCHUCKCOULDCHUCKWOOD' * 50) - _padsize = 2000 - PADLINES = (1, 4, 7, 10, 13, 16, 19, 22, 25) - TEXTLINES = (2, 5, 8, 11, 14, 17, 20, 23, 26) - CIPHERLINES = (3, 6, 9, 12, 15, 18, 21, 24, 27) - - TEST_PADLINE = 'HUCHUGGHOBUXADDHOHPGQBKXQKAOLRL' - TEST_TEXTLINE = 'THISCAKEISUNSATISFACTORYTOMEYES' - TEST_CIPHERLINE = 'BCMAXHRNXUPLTEXRGOQKKQBWKYNTKWD' - - TEST_MSG = \ - 'HOWMUCHCHUCKCOULDAWOODCHUCKCHUCKIFAWOODCHUCKCOULDCHUCKWOOD' \ - 'HOWMUCHCHUCKCOULDAWOODCHUCKCHUCKIFAWOODCHUCKCOULDCHUCKWOOD' \ - 'HOWMUCHCHUCKCOULDAWOODCHUCKCHUCKIFAWOODCHUCKCOULDCHUCKWOOD' \ - 'HOWMUCHCHUCKCOULDAWOODCHUCKCHUCKIFAWOODCHUCKCOULDCHUCKWOOD' \ - 'HOWMUCHCHUCKCOULDAWOODCHUCKCHUCKIFAWOODCHUCKCOULDCHUCKWOOD' \ - 'HOWMUCHCHUCKCOULDAWOODCHUCKCHUCKIFAWOODCHUCKCOULDCHUCKWOOD' \ - 'HOWMUCHCHUCKCOULDAWOODCHUCKCHUCKIFAWOODCHUCKCOULDCHUCKWOOD' \ - 'HOWMUCHCHUCKCOULDAWOODCHUCKCHUCKIFAWOODCHUCKCOULDCHUCKWOOD' \ - 'HOWMUCHCHUCKCOULDAWOODCHUCKCHUCKIFAWOODCHUCKCOULDCHUCKWOOD' \ - 'HOWMUCHCHUCKCOULDAWOODCHUCKCHUCKIFAWOODCHUCKCOULDCHUCKWOOD' \ - 'HOWMUCHCHUCKCOULDAWOODCHUCKCHUCKIFAWOODCHUCKCOULDCHUCKWOOD' \ - 'HOWMUCHCHUCKCOULDAWOODCHUCKCHUCKIFAWOODCHUCKCOULDCHUCKWOOD' \ - 'HOWMUCHCHUCKCOULDAWOODCHUCKCHUCKIFAWOODCHUCKCOULDCHUCKWOOD' \ - 'HOWMUCHCHUCKCOULDAWOODCHUCKCHUCKIFAWOODCHUCKCOULDCHUCKWOOD' \ - 'HOWMUCHCHUCKCOULDAWOODCHUCKCHUCKIFAWOODCHUCKCOULDCHUCKWOOD' \ - 'HOWMUCHCHUCKCOULDAWOODCHUCKCHUCKIFAWOODCHUCKCOULDCHUCKWOOD' \ - 'HOWMUCHCHUCKCOULDAWOODCHUCKCHUCKIFAWOODCHUCKCOULDCHUCKWOOD' \ - 'HOWMUCHCHUCKCOULDAWOODCHUCKCHUCKIFAWOO' - - TEST_CIPHER = \ - 'FMHZRGHRITAMHVAOLBANWMNYPBYDCFCAVXAEEKXUTYXLUCYQVYPWZFSKYI' \ - 'LWKCHZSXLFCMZIEFHXKVUXVNBIQVSNYPTFVIZHSVTDCKWUSZHEHUPLZSUY' \ - 'BTPSMEISGTYDWCXVUCPGHHKXDOUHGCVDTDUQVKFDRDCHFIKTNFGDFODCQS' \ - 'RIWGZBLPTCSXLMPQODYLHQNGWNSCTHNDOZEUXWCEQAZMRGZIQUTUYSKOGW' \ - 'YGYPEDNUZDWBEPUHLWWBHLGADYTCNGEUFKPLQSAMMXCTXWQEOYBNKQAHBV' \ - 'PDKTMQSHDFCFBCVKXVTRSXRTBHAGKNLFASNVNENHHRNGCKXALMIBNZKOTL' \ - 'BZMWGSNMTLDNPXKVQZZUAZCSPWFNRKAMTNMCPHWGLGBVSNFDXSKVUFBZBW' \ - 'WICBUPCWZDUXCZTXHKQBMQNTBHAAGMBPKUIDTHITUEWEPPMACPXERXRYND' \ - 'RWQSBQQMSQRVWZMAQQKUGHLELKFLKHGNFFDHIWUZPDIMIOELSIHMUIZQCW' \ - 'KLPZQIFAXNDRRIIIHOYBGSCIYBIVSRTECEOZSBLYTNCXGQXEWMGIXHKBIL' \ - 'TOKWHGABPMXNAHEWFKIMOQPHVHSYZABWLMLSSDEHQIBNEMEMHCWOUBIIZS' \ - 'XPFWXMQNOTEANYGQBVMZAXNPAMWSUOGFAFFYUTKDZYHFTPYGOMDHESKOZI' \ - 'IPDXAMSAQOTGAQKYPYWWUYGHSBVODAHDSKDVPMLWRCXQXGAXQZBFNKXFKU' \ - 'WUDRWNRKECIQIUEEMQNCAZDDDOQOEGUVFVCTKLTISNOQILEKUYXCYZNHHZ' \ - 'OFHCSLOPPQAFLHHDZANGTXNQSDZSAFLLSGWULVHIDERMTZZHTDHTZPHEFN' \ - 'ORDEIYOVTTAWVTOOXSLZBOPMRCCKSMHQOVFERCOVUMWXFSNEMFALNWGRQC' \ - 'NLWELLXNCHZGXQEUGEVNCWMHRNGUTBKTVEXGASBRCEBSFITOEFSNIBTLME' \ - 'MERMOFVBNTFCTTWEGAIGRZQBBFOKOPXNCWXFBK' - - TEST_PAD = """\ - XXLNWDZOAYXBEGFCGADYHHKQUYOAULZQMRZHQVTRLDUARODERVGBWVVVKECHNQNWKUCLZBWU - - - KUDWNGFTSEGFFSKSVEKZUMLTOSLIZZTFXODBZZMACDFUTESFRBAPYYVTTOCKQBSSTDGPILKE - - - YHSTKXTTGVBAIIZXCUPHICYICDGOBOIUZUEYCMLHPNHXUEKCBWTMKYBKHZLNKTETDXIHYBHF - - - WBOSEXMRLZVHNZSSQSBCKAERRITRBAZWGVZNTGDSIVIZEMBKWDOOBDWIDCZIUHVTKVTSGFDT - - - NRGPNGRNKEVLZVYOAYTUWCDTOLGEQDBSHVRMMYYQIEZWKWZVCPGIAGKPNZEGTLPKMPEILQAC - - - MIPKMYCFMVZKUTVKIPXBKGLFATSDCMYLPYLSTPBARVELNSOUFPZMUTRIRNZLYMDITNXMKLGE - - - QXYRYEAOHGETEQMKTUMARPYMPKONUKYZIHTFGNHIKVOLTLRPMPNFSDHWQGVHBNDCWZCLUHQW - - - GIFBFZKZOFZRRYCBOSBWSNVFXXPSAGOUOXDNBNSOZADYYSKWQUTYNCDNGVLSZNDBCTSIYOUX - - - NNUGLZNKNDSYGRUCXTKLBIMXZMMZAEHVRFYMBFKVDPAEHOYCBXKADZOTRRMULOPAIKCIHKFY - - - BQKKMEXUPLMTKGFIMPMTDVRZEBFEFARDEVQADVKIVNBHNZLEAAGLFIKXHTQWXBPNLXZHFUDZ - - - XYLLVFETIDCYAXGTIHUFUSFMMWTLKZARVQOFGEBKIGWHFFFFKTHPQOMVAVILFLWMRLWPBWVW - - - PFKSLFFWKYQVPHVPQTTVFRLQXHFMGVXVHTNSVZQSETKHXAPPSLHAIAVXWGDFVKOBQLEWPAZY - - - WELQRIFCGSOVFSLYXMSETCTROLNKMDWZSGKREFEPEHCOKSMRTNCDSTHCSQKMKCBYEWZSQHPK - - - UNWWUBKICDYYOSIZWKWRLGGIMYWKMDXOUKYHCUYCACKSFRWWXADQUZTCNYEYCSQEBTCZMSCV - - - NTGCDGFUUCTQWINV........................................................ - - """ - - def setUp(self): - self.m25 = OT.Mod25() - - def test_mk_as_alpha_excludes_j(self): - self.assertTrue('J' not in self.m25._as_alpha.values()) - - def test_mk_as_alpha_dict_has_25_members(self): - self.assertEqual(25, len(self.m25._as_alpha.items())) - - def test_creates_pad_of_desired_length(self): - for width in (72, 33, 99, 111): - pad = self.m25.create_pad(self._padsize, width=width) - lines = [line.strip('.') for line in pad.split()] - actual = len(''.join(lines)) - self.assertEqual(self._padsize, len(''.join(lines)), - 'pad of {0} chars created at width ' - '{1}, actual={2}'.format(self._padsize, - width, actual)) - - def test_is_padline(self): - for lineno in self.PADLINES: - self.assertTrue(self.m25._is_padline(lineno), - 'line {0} is padline'.format(lineno)) - for lineno in self.TEXTLINES: - self.assertFalse(self.m25._is_padline(lineno), - 'line {0} is not padline'.format(lineno)) - for lineno in self.CIPHERLINES: - self.assertFalse(self.m25._is_padline(lineno), - 'line {0} is not padline'.format(lineno)) - - def test_is_textline(self): - for lineno in self.TEXTLINES: - self.assertTrue(self.m25._is_textline(lineno), - 'line {0} is textline'.format(lineno)) - for lineno in self.PADLINES: - self.assertFalse(self.m25._is_textline(lineno), - 'line {0} is not textline'.format(lineno)) - for lineno in self.CIPHERLINES: - self.assertFalse(self.m25._is_textline(lineno), - 'line {0} is not textline'.format(lineno)) - - def test_is_cipherline(self): - for lineno in self.CIPHERLINES: - self.assertTrue(self.m25._is_cipherline(lineno), - 'line {0} is cipherline'.format(lineno)) - for lineno in self.PADLINES: - self.assertFalse(self.m25._is_cipherline(lineno), - 'line {0} is not cipherline'.format(lineno)) - for lineno in self.TEXTLINES: - self.assertFalse(self.m25._is_cipherline(lineno), - 'line {0} is not cipherline'.format(lineno)) - - def test_make_cipherline_from_padline_and_textline(self): - actual = \ - self.m25._cipherline_from_padline_and_textline(self.TEST_PADLINE, - self.TEST_TEXTLINE) - self.assertEqual(self.TEST_CIPHERLINE, actual) - - def test_make_textline_from_cipherline_and_padline(self): - actual = self.m25._textline_from_cipherline_and_padline( - self.TEST_CIPHERLINE, self.TEST_PADLINE) - self.assertEqual(self.TEST_TEXTLINE, actual) - - def test_encode_equals_expected(self): - ciphertext = OT.mod25encode(self.TEST_MSG, self.TEST_PAD) - self.assertEqual(self.TEST_CIPHER, ciphertext) - - def test_decode_equals_expected(self): - text = OT.mod25decode(self.TEST_CIPHER, self.TEST_PAD) - self.assertEqual(self.TEST_MSG, text) - - -class TestOneTimePad(unittest.TestCase): - - def test_get_randint_on_nonexistent_randomness_file_fails_ioerror(self): - OT._DEV_URANDOM['fp'] = None - self.assertRaises(IOError, OT._get_randint, - 25, randomness_file='/foo/bar/busted/borken', - fallback_to_fake=False) - - def test_get_randint_on_nonexistent_randomness_file_uses_fake(self): - OT._DEV_URANDOM['fp'] = None - random_int = OT._get_randint(32, randomness_file='/broke/as/joke') - self.assertTrue(random_int in range(0, 255)) - - -if __name__ == '__main__': - unittest.main() diff --git a/one-time-pad/onetimepad.py b/one-time-pad/onetimepad.py deleted file mode 100644 index 1ea151f..0000000 --- a/one-time-pad/onetimepad.py +++ /dev/null @@ -1,220 +0,0 @@ -from itertools import izip - -DEFAULT_PAD_WIDTH = 72 - - -def mod25encode(msg, pad): - mod25 = Mod25(pad=pad) - return mod25.encode(msg) - - -def mod25decode(msg, pad): - mod25 = Mod25(pad=pad) - return mod25.decode(msg) - - -class Mod25(object): - _pad_modulo = 3 - _padline_offset = -2 - _textline_offset = -1 - _cipher_floor = 1 - _cipher_ceil = 25 - _nullchar = '.' - - def __init__(self, pad=''): - self.pad = pad - self._as_alpha = {} - self._as_nums = {} - self._mk_as_alpha_as_nums() - - def _mk_as_alpha_as_nums(self): - as_alpha = {} - as_nums = {} - a_chr = ord('A') - past_j = False - - for char in range(self._cipher_ceil + 1): - letter = chr(a_chr + char) - if letter != 'J': - key = char + (1 if not past_j else 0) - as_alpha[key] = letter - else: - past_j = True - - for key, val in as_alpha.iteritems(): - as_nums[val] = key - - self._as_alpha.update(as_alpha) - self._as_nums.update(as_nums) - - def encode(self, msg): - ret = [] - filled = list(self._text_padfill(msg)) - for i, line in enumerate(self._text_cipherfill(filled)): - lineno = i + 1 - if self._is_cipherline(lineno): - ret.append(line) - return ''.join(ret).strip(self._nullchar) - - def decode(self, ciphertext): - ret = [] - filled = list(self._cipher_padfill(ciphertext)) - for i, line in enumerate(self._cipher_textfill(filled)): - lineno = i + 1 - if self._is_textline(lineno): - ret.append(line) - return ''.join(ret).strip(self._nullchar) - - def create_pad(self, length, width=DEFAULT_PAD_WIDTH): - return '\n'.join(self.create_pad_lines(length, width=width)) - - def create_pad_lines(self, length, width=DEFAULT_PAD_WIDTH): - chars = self._create_chars_for_pad(length) - lines = _chunk_chars_into_lines(chars, self._nullchar, width=width) - for line in lines: - yield line - yield '' - yield '' - - def _create_chars_for_pad(self, length): - chars = [] - for char in range(length): - chars.append(self._as_alpha[_get_randint(self._cipher_ceil)]) - return ''.join(chars) - - def _ensure_pad_is_lines(self): - if isinstance(self.pad, basestring): - self.pad = self.pad.splitlines() - - def _text_padfill(self, text): - self._ensure_pad_is_lines() - padlines = [line.strip() for line in self.pad if line.strip()] - textlines = _chunk_chars_into_lines(text, self._nullchar, - _get_textwidth(padlines)) - for textline, padline in izip(textlines, padlines): - yield padline - yield textline - yield '' - - def _cipher_padfill(self, ciphertext): - self._ensure_pad_is_lines() - padlines = [line.strip() for line in self.pad if line.strip()] - cipherlines = _chunk_chars_into_lines(ciphertext, self._nullchar, - _get_textwidth(padlines)) - for cipherline, padline in izip(cipherlines, padlines): - yield padline - yield '' - yield cipherline - - def _text_cipherfill(self, padfilled_text_lines): - for i, line in enumerate(padfilled_text_lines): - lineno = i + 1 - if self._is_cipherline(lineno): - padline = padfilled_text_lines[i - abs(self._padline_offset)] - textline = padfilled_text_lines[i - abs(self._textline_offset)] - yield padline - yield textline - yield self._cipherline_from_padline_and_textline(padline, - textline) - - def _cipher_textfill(self, padfilled_cipher_lines): - for i, line in enumerate(padfilled_cipher_lines): - lineno = i + 1 - if self._is_cipherline(lineno): - padline = padfilled_cipher_lines[i - abs(self._padline_offset)] - textline = \ - padfilled_cipher_lines[i - abs(self._textline_offset)] - yield padline - yield self._textline_from_cipherline_and_padline(line, padline) - yield line - - def _cipherline_from_padline_and_textline(self, padline, textline): - ret = [] - for padchar, textchar in izip(padline, textline): - if textchar == self._nullchar: - ret.append(self._nullchar) - continue - charnum = self._as_nums[padchar] + self._as_nums[textchar] - idx = charnum if charnum <= self._cipher_ceil else \ - charnum % self._cipher_ceil - ret.append(self._as_alpha[idx]) - return ''.join(ret) - - def _textline_from_cipherline_and_padline(self, cipherline, padline): - ret = [] - for ciphercar, padchar in izip(cipherline, padline): - if ciphercar == self._nullchar: - ret.append(self._nullchar) - continue - charnum = self._as_nums[ciphercar] - self._as_nums[padchar] - idx = charnum if charnum <= self._cipher_ceil else \ - charnum % self._cipher_ceil - if idx < 0: - idx = self._cipher_ceil + idx - ret.append(self._as_alpha[idx]) - return ''.join(ret) - - def _is_padline(self, lineno): - return self._is_cipherline(lineno + abs(self._padline_offset)) - - def _is_textline(self, lineno): - return self._is_cipherline(lineno + abs(self._textline_offset)) - - def _is_cipherline(self, lineno): - return not lineno % self._pad_modulo - - -def _chunk_chars_into_lines(chars, nullchar, width=DEFAULT_PAD_WIDTH): - lines = [] - for chunk in _as_line_chunks(chars, nullchar, width=width): - lines.append(chunk) - return lines - - -def _as_line_chunks(chars, nullchar, width=DEFAULT_PAD_WIDTH): - chunk = [] - for char in chars.replace('\n', ''): - chunk.append(char) - if len(chunk) == width: - yield ''.join(chunk) - chunk = [] - if len(chunk) < width: - chunk += ([nullchar] * (width - len(chunk))) - yield ''.join(chunk) - - -def _get_textwidth(textlines): - return max([len(line) for line in textlines]) - - -def _get_randint(modulo, randomness_file='/dev/urandom', - fallback_to_fake=True): - if not _DEV_URANDOM.get('fp'): - _get_urandom_fp(randomness_file=randomness_file, - fallback_to_fake=fallback_to_fake) - ret = ord(_DEV_URANDOM['fp'].read(1)) % modulo - return ret if ret != 0 else _get_randint(modulo) - - -class _FakeDevUrandom(object): - - @staticmethod - def read(nchars): - import random - ret = [] - for i in range(0, nchars): - ret.append(chr(random.randint(0, 255))) - return ''.join(ret) - - -def _get_urandom_fp(randomness_file='/dev/urandom', fallback_to_fake=True): - try: - _DEV_URANDOM['fp'] = open(randomness_file) - except (OSError, IOError): - if fallback_to_fake: - _DEV_URANDOM['fp'] = _FakeDevUrandom() - else: - raise - - -_DEV_URANDOM = {} diff --git a/one-time-pad/pavement.py b/one-time-pad/pavement.py deleted file mode 100644 index ca5722c..0000000 --- a/one-time-pad/pavement.py +++ /dev/null @@ -1,26 +0,0 @@ -from paver.easy import * -from paver.setuputils import setup - - -README = path.getcwd()/'README' -SETUP_ARGS = Bunch( - name='OneTimePad', - version='0.1.0', - author='Dan Buch', - author_email='daniel.buch@gmail.com', - url='http://github.com/meatballhat/OneTimePad', - description='like so: http://en.wikipedia.org/wiki/One-time_pad', - long_description=README.bytes(), - py_modules=['onetimepad'], - license='MIT', - platforms=['any'], -) - - -setup(**SETUP_ARGS) - - -@task -@needs(['generate_setup', 'minilib', 'setuptools.command.sdist']) -def sdist(): - pass diff --git a/perl-practice/.gitignore b/perl-practice/.gitignore deleted file mode 100644 index 3a91107..0000000 --- a/perl-practice/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ -*/*.log -*/*.pid -*/*.sock - -web/nginx.conf -web/lighttpd.conf -web/cgiwrap-fcgi.pl -web/*_temp/* -web/lighttpd-*/ \ No newline at end of file diff --git a/perl-practice/README.pod b/perl-practice/README.pod deleted file mode 100644 index c195fc5..0000000 --- a/perl-practice/README.pod +++ /dev/null @@ -1,7 +0,0 @@ -=encoding utf8 - -=head1 I'm learning me some perl! - -After a long absence from having anything to do with -"da camel," I'm getting familiar again. - diff --git a/perl-practice/cli/alice-in-wonderland.txt b/perl-practice/cli/alice-in-wonderland.txt deleted file mode 100644 index 4565d28..0000000 --- a/perl-practice/cli/alice-in-wonderland.txt +++ /dev/null @@ -1,3735 +0,0 @@ -Project Gutenberg's Alice's Adventures in Wonderland, by Lewis Carroll - -This eBook is for the use of anyone anywhere at no cost and with -almost no restrictions whatsoever. You may copy it, give it away or -re-use it under the terms of the Project Gutenberg License included -with this eBook or online at www.gutenberg.org - - -Title: Alice's Adventures in Wonderland - -Author: Lewis Carroll - -Posting Date: June 25, 2008 [EBook #11] -Release Date: March, 1994 - -Language: English - - -*** START OF THIS PROJECT GUTENBERG EBOOK ALICE'S ADVENTURES IN WONDERLAND *** - - - - - - - - - - -ALICE'S ADVENTURES IN WONDERLAND - -Lewis Carroll - -THE MILLENNIUM FULCRUM EDITION 3.0 - - - - -CHAPTER 1. Down the Rabbit-Hole - -Alice was beginning to get very tired of sitting by her sister on the -bank, and of having nothing to do: once or twice she had peeped into the -book her sister was reading, but it had no pictures or conversations in -it, 'and what is the use of a book,' thought Alice 'without pictures or -conversation?' - -So she was considering in her own mind (as well as she could, for the -hot day made her feel very sleepy and stupid), whether the pleasure -of making a daisy-chain would be worth the trouble of getting up and -picking the daisies, when suddenly a White Rabbit with pink eyes ran -close by her. - -There was nothing so VERY remarkable in that; nor did Alice think it so -VERY much out of the way to hear the Rabbit say to itself, 'Oh dear! -Oh dear! I shall be late!' (when she thought it over afterwards, it -occurred to her that she ought to have wondered at this, but at the time -it all seemed quite natural); but when the Rabbit actually TOOK A WATCH -OUT OF ITS WAISTCOAT-POCKET, and looked at it, and then hurried on, -Alice started to her feet, for it flashed across her mind that she had -never before seen a rabbit with either a waistcoat-pocket, or a watch -to take out of it, and burning with curiosity, she ran across the field -after it, and fortunately was just in time to see it pop down a large -rabbit-hole under the hedge. - -In another moment down went Alice after it, never once considering how -in the world she was to get out again. - -The rabbit-hole went straight on like a tunnel for some way, and then -dipped suddenly down, so suddenly that Alice had not a moment to think -about stopping herself before she found herself falling down a very deep -well. - -Either the well was very deep, or she fell very slowly, for she had -plenty of time as she went down to look about her and to wonder what was -going to happen next. First, she tried to look down and make out what -she was coming to, but it was too dark to see anything; then she -looked at the sides of the well, and noticed that they were filled with -cupboards and book-shelves; here and there she saw maps and pictures -hung upon pegs. She took down a jar from one of the shelves as -she passed; it was labelled 'ORANGE MARMALADE', but to her great -disappointment it was empty: she did not like to drop the jar for fear -of killing somebody, so managed to put it into one of the cupboards as -she fell past it. - -'Well!' thought Alice to herself, 'after such a fall as this, I shall -think nothing of tumbling down stairs! How brave they'll all think me at -home! Why, I wouldn't say anything about it, even if I fell off the top -of the house!' (Which was very likely true.) - -Down, down, down. Would the fall NEVER come to an end! 'I wonder how -many miles I've fallen by this time?' she said aloud. 'I must be getting -somewhere near the centre of the earth. Let me see: that would be four -thousand miles down, I think--' (for, you see, Alice had learnt several -things of this sort in her lessons in the schoolroom, and though this -was not a VERY good opportunity for showing off her knowledge, as there -was no one to listen to her, still it was good practice to say it over) -'--yes, that's about the right distance--but then I wonder what Latitude -or Longitude I've got to?' (Alice had no idea what Latitude was, or -Longitude either, but thought they were nice grand words to say.) - -Presently she began again. 'I wonder if I shall fall right THROUGH the -earth! How funny it'll seem to come out among the people that walk with -their heads downward! The Antipathies, I think--' (she was rather glad -there WAS no one listening, this time, as it didn't sound at all the -right word) '--but I shall have to ask them what the name of the country -is, you know. Please, Ma'am, is this New Zealand or Australia?' (and -she tried to curtsey as she spoke--fancy CURTSEYING as you're falling -through the air! Do you think you could manage it?) 'And what an -ignorant little girl she'll think me for asking! No, it'll never do to -ask: perhaps I shall see it written up somewhere.' - -Down, down, down. There was nothing else to do, so Alice soon began -talking again. 'Dinah'll miss me very much to-night, I should think!' -(Dinah was the cat.) 'I hope they'll remember her saucer of milk at -tea-time. Dinah my dear! I wish you were down here with me! There are no -mice in the air, I'm afraid, but you might catch a bat, and that's very -like a mouse, you know. But do cats eat bats, I wonder?' And here Alice -began to get rather sleepy, and went on saying to herself, in a dreamy -sort of way, 'Do cats eat bats? Do cats eat bats?' and sometimes, 'Do -bats eat cats?' for, you see, as she couldn't answer either question, -it didn't much matter which way she put it. She felt that she was dozing -off, and had just begun to dream that she was walking hand in hand with -Dinah, and saying to her very earnestly, 'Now, Dinah, tell me the truth: -did you ever eat a bat?' when suddenly, thump! thump! down she came upon -a heap of sticks and dry leaves, and the fall was over. - -Alice was not a bit hurt, and she jumped up on to her feet in a moment: -she looked up, but it was all dark overhead; before her was another -long passage, and the White Rabbit was still in sight, hurrying down it. -There was not a moment to be lost: away went Alice like the wind, and -was just in time to hear it say, as it turned a corner, 'Oh my ears -and whiskers, how late it's getting!' She was close behind it when she -turned the corner, but the Rabbit was no longer to be seen: she found -herself in a long, low hall, which was lit up by a row of lamps hanging -from the roof. - -There were doors all round the hall, but they were all locked; and when -Alice had been all the way down one side and up the other, trying every -door, she walked sadly down the middle, wondering how she was ever to -get out again. - -Suddenly she came upon a little three-legged table, all made of solid -glass; there was nothing on it except a tiny golden key, and Alice's -first thought was that it might belong to one of the doors of the hall; -but, alas! either the locks were too large, or the key was too small, -but at any rate it would not open any of them. However, on the second -time round, she came upon a low curtain she had not noticed before, and -behind it was a little door about fifteen inches high: she tried the -little golden key in the lock, and to her great delight it fitted! - -Alice opened the door and found that it led into a small passage, not -much larger than a rat-hole: she knelt down and looked along the passage -into the loveliest garden you ever saw. How she longed to get out of -that dark hall, and wander about among those beds of bright flowers and -those cool fountains, but she could not even get her head through the -doorway; 'and even if my head would go through,' thought poor Alice, 'it -would be of very little use without my shoulders. Oh, how I wish I could -shut up like a telescope! I think I could, if I only know how to begin.' -For, you see, so many out-of-the-way things had happened lately, -that Alice had begun to think that very few things indeed were really -impossible. - -There seemed to be no use in waiting by the little door, so she went -back to the table, half hoping she might find another key on it, or at -any rate a book of rules for shutting people up like telescopes: this -time she found a little bottle on it, ('which certainly was not here -before,' said Alice,) and round the neck of the bottle was a paper -label, with the words 'DRINK ME' beautifully printed on it in large -letters. - -It was all very well to say 'Drink me,' but the wise little Alice was -not going to do THAT in a hurry. 'No, I'll look first,' she said, 'and -see whether it's marked "poison" or not'; for she had read several nice -little histories about children who had got burnt, and eaten up by wild -beasts and other unpleasant things, all because they WOULD not remember -the simple rules their friends had taught them: such as, that a red-hot -poker will burn you if you hold it too long; and that if you cut your -finger VERY deeply with a knife, it usually bleeds; and she had never -forgotten that, if you drink much from a bottle marked 'poison,' it is -almost certain to disagree with you, sooner or later. - -However, this bottle was NOT marked 'poison,' so Alice ventured to taste -it, and finding it very nice, (it had, in fact, a sort of mixed flavour -of cherry-tart, custard, pine-apple, roast turkey, toffee, and hot -buttered toast,) she very soon finished it off. - - * * * * * * * - - * * * * * * - - * * * * * * * - -'What a curious feeling!' said Alice; 'I must be shutting up like a -telescope.' - -And so it was indeed: she was now only ten inches high, and her face -brightened up at the thought that she was now the right size for going -through the little door into that lovely garden. First, however, she -waited for a few minutes to see if she was going to shrink any further: -she felt a little nervous about this; 'for it might end, you know,' said -Alice to herself, 'in my going out altogether, like a candle. I wonder -what I should be like then?' And she tried to fancy what the flame of a -candle is like after the candle is blown out, for she could not remember -ever having seen such a thing. - -After a while, finding that nothing more happened, she decided on going -into the garden at once; but, alas for poor Alice! when she got to the -door, she found she had forgotten the little golden key, and when she -went back to the table for it, she found she could not possibly reach -it: she could see it quite plainly through the glass, and she tried her -best to climb up one of the legs of the table, but it was too slippery; -and when she had tired herself out with trying, the poor little thing -sat down and cried. - -'Come, there's no use in crying like that!' said Alice to herself, -rather sharply; 'I advise you to leave off this minute!' She generally -gave herself very good advice, (though she very seldom followed it), -and sometimes she scolded herself so severely as to bring tears into -her eyes; and once she remembered trying to box her own ears for having -cheated herself in a game of croquet she was playing against herself, -for this curious child was very fond of pretending to be two people. -'But it's no use now,' thought poor Alice, 'to pretend to be two people! -Why, there's hardly enough of me left to make ONE respectable person!' - -Soon her eye fell on a little glass box that was lying under the table: -she opened it, and found in it a very small cake, on which the words -'EAT ME' were beautifully marked in currants. 'Well, I'll eat it,' said -Alice, 'and if it makes me grow larger, I can reach the key; and if it -makes me grow smaller, I can creep under the door; so either way I'll -get into the garden, and I don't care which happens!' - -She ate a little bit, and said anxiously to herself, 'Which way? Which -way?', holding her hand on the top of her head to feel which way it was -growing, and she was quite surprised to find that she remained the same -size: to be sure, this generally happens when one eats cake, but Alice -had got so much into the way of expecting nothing but out-of-the-way -things to happen, that it seemed quite dull and stupid for life to go on -in the common way. - -So she set to work, and very soon finished off the cake. - - * * * * * * * - - * * * * * * - - * * * * * * * - - - - -CHAPTER 2. The Pool of Tears - -'Curiouser and curiouser!' cried Alice (she was so much surprised, that -for the moment she quite forgot how to speak good English); 'now I'm -opening out like the largest telescope that ever was! Good-bye, feet!' -(for when she looked down at her feet, they seemed to be almost out of -sight, they were getting so far off). 'Oh, my poor little feet, I wonder -who will put on your shoes and stockings for you now, dears? I'm sure -_I_ shan't be able! I shall be a great deal too far off to trouble -myself about you: you must manage the best way you can;--but I must be -kind to them,' thought Alice, 'or perhaps they won't walk the way I want -to go! Let me see: I'll give them a new pair of boots every Christmas.' - -And she went on planning to herself how she would manage it. 'They must -go by the carrier,' she thought; 'and how funny it'll seem, sending -presents to one's own feet! And how odd the directions will look! - - ALICE'S RIGHT FOOT, ESQ. - HEARTHRUG, - NEAR THE FENDER, - (WITH ALICE'S LOVE). - -Oh dear, what nonsense I'm talking!' - -Just then her head struck against the roof of the hall: in fact she was -now more than nine feet high, and she at once took up the little golden -key and hurried off to the garden door. - -Poor Alice! It was as much as she could do, lying down on one side, to -look through into the garden with one eye; but to get through was more -hopeless than ever: she sat down and began to cry again. - -'You ought to be ashamed of yourself,' said Alice, 'a great girl like -you,' (she might well say this), 'to go on crying in this way! Stop this -moment, I tell you!' But she went on all the same, shedding gallons of -tears, until there was a large pool all round her, about four inches -deep and reaching half down the hall. - -After a time she heard a little pattering of feet in the distance, and -she hastily dried her eyes to see what was coming. It was the White -Rabbit returning, splendidly dressed, with a pair of white kid gloves in -one hand and a large fan in the other: he came trotting along in a great -hurry, muttering to himself as he came, 'Oh! the Duchess, the Duchess! -Oh! won't she be savage if I've kept her waiting!' Alice felt so -desperate that she was ready to ask help of any one; so, when the Rabbit -came near her, she began, in a low, timid voice, 'If you please, sir--' -The Rabbit started violently, dropped the white kid gloves and the fan, -and skurried away into the darkness as hard as he could go. - -Alice took up the fan and gloves, and, as the hall was very hot, she -kept fanning herself all the time she went on talking: 'Dear, dear! How -queer everything is to-day! And yesterday things went on just as usual. -I wonder if I've been changed in the night? Let me think: was I the -same when I got up this morning? I almost think I can remember feeling a -little different. But if I'm not the same, the next question is, Who -in the world am I? Ah, THAT'S the great puzzle!' And she began thinking -over all the children she knew that were of the same age as herself, to -see if she could have been changed for any of them. - -'I'm sure I'm not Ada,' she said, 'for her hair goes in such long -ringlets, and mine doesn't go in ringlets at all; and I'm sure I can't -be Mabel, for I know all sorts of things, and she, oh! she knows such a -very little! Besides, SHE'S she, and I'm I, and--oh dear, how puzzling -it all is! I'll try if I know all the things I used to know. Let me -see: four times five is twelve, and four times six is thirteen, and -four times seven is--oh dear! I shall never get to twenty at that rate! -However, the Multiplication Table doesn't signify: let's try Geography. -London is the capital of Paris, and Paris is the capital of Rome, and -Rome--no, THAT'S all wrong, I'm certain! I must have been changed for -Mabel! I'll try and say "How doth the little--"' and she crossed her -hands on her lap as if she were saying lessons, and began to repeat it, -but her voice sounded hoarse and strange, and the words did not come the -same as they used to do:-- - - 'How doth the little crocodile - Improve his shining tail, - And pour the waters of the Nile - On every golden scale! - - 'How cheerfully he seems to grin, - How neatly spread his claws, - And welcome little fishes in - With gently smiling jaws!' - -'I'm sure those are not the right words,' said poor Alice, and her eyes -filled with tears again as she went on, 'I must be Mabel after all, and -I shall have to go and live in that poky little house, and have next to -no toys to play with, and oh! ever so many lessons to learn! No, I've -made up my mind about it; if I'm Mabel, I'll stay down here! It'll be no -use their putting their heads down and saying "Come up again, dear!" I -shall only look up and say "Who am I then? Tell me that first, and then, -if I like being that person, I'll come up: if not, I'll stay down here -till I'm somebody else"--but, oh dear!' cried Alice, with a sudden burst -of tears, 'I do wish they WOULD put their heads down! I am so VERY tired -of being all alone here!' - -As she said this she looked down at her hands, and was surprised to see -that she had put on one of the Rabbit's little white kid gloves while -she was talking. 'How CAN I have done that?' she thought. 'I must -be growing small again.' She got up and went to the table to measure -herself by it, and found that, as nearly as she could guess, she was now -about two feet high, and was going on shrinking rapidly: she soon found -out that the cause of this was the fan she was holding, and she dropped -it hastily, just in time to avoid shrinking away altogether. - -'That WAS a narrow escape!' said Alice, a good deal frightened at the -sudden change, but very glad to find herself still in existence; 'and -now for the garden!' and she ran with all speed back to the little door: -but, alas! the little door was shut again, and the little golden key was -lying on the glass table as before, 'and things are worse than ever,' -thought the poor child, 'for I never was so small as this before, never! -And I declare it's too bad, that it is!' - -As she said these words her foot slipped, and in another moment, splash! -she was up to her chin in salt water. Her first idea was that she -had somehow fallen into the sea, 'and in that case I can go back by -railway,' she said to herself. (Alice had been to the seaside once in -her life, and had come to the general conclusion, that wherever you go -to on the English coast you find a number of bathing machines in the -sea, some children digging in the sand with wooden spades, then a row -of lodging houses, and behind them a railway station.) However, she soon -made out that she was in the pool of tears which she had wept when she -was nine feet high. - -'I wish I hadn't cried so much!' said Alice, as she swam about, trying -to find her way out. 'I shall be punished for it now, I suppose, by -being drowned in my own tears! That WILL be a queer thing, to be sure! -However, everything is queer to-day.' - -Just then she heard something splashing about in the pool a little way -off, and she swam nearer to make out what it was: at first she thought -it must be a walrus or hippopotamus, but then she remembered how small -she was now, and she soon made out that it was only a mouse that had -slipped in like herself. - -'Would it be of any use, now,' thought Alice, 'to speak to this mouse? -Everything is so out-of-the-way down here, that I should think very -likely it can talk: at any rate, there's no harm in trying.' So she -began: 'O Mouse, do you know the way out of this pool? I am very tired -of swimming about here, O Mouse!' (Alice thought this must be the right -way of speaking to a mouse: she had never done such a thing before, but -she remembered having seen in her brother's Latin Grammar, 'A mouse--of -a mouse--to a mouse--a mouse--O mouse!') The Mouse looked at her rather -inquisitively, and seemed to her to wink with one of its little eyes, -but it said nothing. - -'Perhaps it doesn't understand English,' thought Alice; 'I daresay it's -a French mouse, come over with William the Conqueror.' (For, with all -her knowledge of history, Alice had no very clear notion how long ago -anything had happened.) So she began again: 'Ou est ma chatte?' which -was the first sentence in her French lesson-book. The Mouse gave a -sudden leap out of the water, and seemed to quiver all over with fright. -'Oh, I beg your pardon!' cried Alice hastily, afraid that she had hurt -the poor animal's feelings. 'I quite forgot you didn't like cats.' - -'Not like cats!' cried the Mouse, in a shrill, passionate voice. 'Would -YOU like cats if you were me?' - -'Well, perhaps not,' said Alice in a soothing tone: 'don't be angry -about it. And yet I wish I could show you our cat Dinah: I think you'd -take a fancy to cats if you could only see her. She is such a dear quiet -thing,' Alice went on, half to herself, as she swam lazily about in the -pool, 'and she sits purring so nicely by the fire, licking her paws and -washing her face--and she is such a nice soft thing to nurse--and she's -such a capital one for catching mice--oh, I beg your pardon!' cried -Alice again, for this time the Mouse was bristling all over, and she -felt certain it must be really offended. 'We won't talk about her any -more if you'd rather not.' - -'We indeed!' cried the Mouse, who was trembling down to the end of his -tail. 'As if I would talk on such a subject! Our family always HATED -cats: nasty, low, vulgar things! Don't let me hear the name again!' - -'I won't indeed!' said Alice, in a great hurry to change the subject of -conversation. 'Are you--are you fond--of--of dogs?' The Mouse did not -answer, so Alice went on eagerly: 'There is such a nice little dog near -our house I should like to show you! A little bright-eyed terrier, you -know, with oh, such long curly brown hair! And it'll fetch things when -you throw them, and it'll sit up and beg for its dinner, and all sorts -of things--I can't remember half of them--and it belongs to a farmer, -you know, and he says it's so useful, it's worth a hundred pounds! He -says it kills all the rats and--oh dear!' cried Alice in a sorrowful -tone, 'I'm afraid I've offended it again!' For the Mouse was swimming -away from her as hard as it could go, and making quite a commotion in -the pool as it went. - -So she called softly after it, 'Mouse dear! Do come back again, and we -won't talk about cats or dogs either, if you don't like them!' When the -Mouse heard this, it turned round and swam slowly back to her: its -face was quite pale (with passion, Alice thought), and it said in a low -trembling voice, 'Let us get to the shore, and then I'll tell you my -history, and you'll understand why it is I hate cats and dogs.' - -It was high time to go, for the pool was getting quite crowded with the -birds and animals that had fallen into it: there were a Duck and a Dodo, -a Lory and an Eaglet, and several other curious creatures. Alice led the -way, and the whole party swam to the shore. - - - - -CHAPTER 3. A Caucus-Race and a Long Tale - -They were indeed a queer-looking party that assembled on the bank--the -birds with draggled feathers, the animals with their fur clinging close -to them, and all dripping wet, cross, and uncomfortable. - -The first question of course was, how to get dry again: they had a -consultation about this, and after a few minutes it seemed quite natural -to Alice to find herself talking familiarly with them, as if she had -known them all her life. Indeed, she had quite a long argument with the -Lory, who at last turned sulky, and would only say, 'I am older than -you, and must know better'; and this Alice would not allow without -knowing how old it was, and, as the Lory positively refused to tell its -age, there was no more to be said. - -At last the Mouse, who seemed to be a person of authority among them, -called out, 'Sit down, all of you, and listen to me! I'LL soon make you -dry enough!' They all sat down at once, in a large ring, with the Mouse -in the middle. Alice kept her eyes anxiously fixed on it, for she felt -sure she would catch a bad cold if she did not get dry very soon. - -'Ahem!' said the Mouse with an important air, 'are you all ready? This -is the driest thing I know. Silence all round, if you please! "William -the Conqueror, whose cause was favoured by the pope, was soon submitted -to by the English, who wanted leaders, and had been of late much -accustomed to usurpation and conquest. Edwin and Morcar, the earls of -Mercia and Northumbria--"' - -'Ugh!' said the Lory, with a shiver. - -'I beg your pardon!' said the Mouse, frowning, but very politely: 'Did -you speak?' - -'Not I!' said the Lory hastily. - -'I thought you did,' said the Mouse. '--I proceed. "Edwin and Morcar, -the earls of Mercia and Northumbria, declared for him: and even Stigand, -the patriotic archbishop of Canterbury, found it advisable--"' - -'Found WHAT?' said the Duck. - -'Found IT,' the Mouse replied rather crossly: 'of course you know what -"it" means.' - -'I know what "it" means well enough, when I find a thing,' said the -Duck: 'it's generally a frog or a worm. The question is, what did the -archbishop find?' - -The Mouse did not notice this question, but hurriedly went on, '"--found -it advisable to go with Edgar Atheling to meet William and offer him the -crown. William's conduct at first was moderate. But the insolence of his -Normans--" How are you getting on now, my dear?' it continued, turning -to Alice as it spoke. - -'As wet as ever,' said Alice in a melancholy tone: 'it doesn't seem to -dry me at all.' - -'In that case,' said the Dodo solemnly, rising to its feet, 'I move -that the meeting adjourn, for the immediate adoption of more energetic -remedies--' - -'Speak English!' said the Eaglet. 'I don't know the meaning of half -those long words, and, what's more, I don't believe you do either!' And -the Eaglet bent down its head to hide a smile: some of the other birds -tittered audibly. - -'What I was going to say,' said the Dodo in an offended tone, 'was, that -the best thing to get us dry would be a Caucus-race.' - -'What IS a Caucus-race?' said Alice; not that she wanted much to know, -but the Dodo had paused as if it thought that SOMEBODY ought to speak, -and no one else seemed inclined to say anything. - -'Why,' said the Dodo, 'the best way to explain it is to do it.' (And, as -you might like to try the thing yourself, some winter day, I will tell -you how the Dodo managed it.) - -First it marked out a race-course, in a sort of circle, ('the exact -shape doesn't matter,' it said,) and then all the party were placed -along the course, here and there. There was no 'One, two, three, and -away,' but they began running when they liked, and left off when they -liked, so that it was not easy to know when the race was over. However, -when they had been running half an hour or so, and were quite dry again, -the Dodo suddenly called out 'The race is over!' and they all crowded -round it, panting, and asking, 'But who has won?' - -This question the Dodo could not answer without a great deal of thought, -and it sat for a long time with one finger pressed upon its forehead -(the position in which you usually see Shakespeare, in the pictures -of him), while the rest waited in silence. At last the Dodo said, -'EVERYBODY has won, and all must have prizes.' - -'But who is to give the prizes?' quite a chorus of voices asked. - -'Why, SHE, of course,' said the Dodo, pointing to Alice with one finger; -and the whole party at once crowded round her, calling out in a confused -way, 'Prizes! Prizes!' - -Alice had no idea what to do, and in despair she put her hand in her -pocket, and pulled out a box of comfits, (luckily the salt water had -not got into it), and handed them round as prizes. There was exactly one -a-piece all round. - -'But she must have a prize herself, you know,' said the Mouse. - -'Of course,' the Dodo replied very gravely. 'What else have you got in -your pocket?' he went on, turning to Alice. - -'Only a thimble,' said Alice sadly. - -'Hand it over here,' said the Dodo. - -Then they all crowded round her once more, while the Dodo solemnly -presented the thimble, saying 'We beg your acceptance of this elegant -thimble'; and, when it had finished this short speech, they all cheered. - -Alice thought the whole thing very absurd, but they all looked so grave -that she did not dare to laugh; and, as she could not think of anything -to say, she simply bowed, and took the thimble, looking as solemn as she -could. - -The next thing was to eat the comfits: this caused some noise and -confusion, as the large birds complained that they could not taste -theirs, and the small ones choked and had to be patted on the back. -However, it was over at last, and they sat down again in a ring, and -begged the Mouse to tell them something more. - -'You promised to tell me your history, you know,' said Alice, 'and why -it is you hate--C and D,' she added in a whisper, half afraid that it -would be offended again. - -'Mine is a long and a sad tale!' said the Mouse, turning to Alice, and -sighing. - -'It IS a long tail, certainly,' said Alice, looking down with wonder at -the Mouse's tail; 'but why do you call it sad?' And she kept on puzzling -about it while the Mouse was speaking, so that her idea of the tale was -something like this:-- - - 'Fury said to a - mouse, That he - met in the - house, - "Let us - both go to - law: I will - prosecute - YOU.--Come, - I'll take no - denial; We - must have a - trial: For - really this - morning I've - nothing - to do." - Said the - mouse to the - cur, "Such - a trial, - dear Sir, - With - no jury - or judge, - would be - wasting - our - breath." - "I'll be - judge, I'll - be jury," - Said - cunning - old Fury: - "I'll - try the - whole - cause, - and - condemn - you - to - death."' - - -'You are not attending!' said the Mouse to Alice severely. 'What are you -thinking of?' - -'I beg your pardon,' said Alice very humbly: 'you had got to the fifth -bend, I think?' - -'I had NOT!' cried the Mouse, sharply and very angrily. - -'A knot!' said Alice, always ready to make herself useful, and looking -anxiously about her. 'Oh, do let me help to undo it!' - -'I shall do nothing of the sort,' said the Mouse, getting up and walking -away. 'You insult me by talking such nonsense!' - -'I didn't mean it!' pleaded poor Alice. 'But you're so easily offended, -you know!' - -The Mouse only growled in reply. - -'Please come back and finish your story!' Alice called after it; and the -others all joined in chorus, 'Yes, please do!' but the Mouse only shook -its head impatiently, and walked a little quicker. - -'What a pity it wouldn't stay!' sighed the Lory, as soon as it was quite -out of sight; and an old Crab took the opportunity of saying to her -daughter 'Ah, my dear! Let this be a lesson to you never to lose -YOUR temper!' 'Hold your tongue, Ma!' said the young Crab, a little -snappishly. 'You're enough to try the patience of an oyster!' - -'I wish I had our Dinah here, I know I do!' said Alice aloud, addressing -nobody in particular. 'She'd soon fetch it back!' - -'And who is Dinah, if I might venture to ask the question?' said the -Lory. - -Alice replied eagerly, for she was always ready to talk about her pet: -'Dinah's our cat. And she's such a capital one for catching mice you -can't think! And oh, I wish you could see her after the birds! Why, -she'll eat a little bird as soon as look at it!' - -This speech caused a remarkable sensation among the party. Some of the -birds hurried off at once: one old Magpie began wrapping itself up very -carefully, remarking, 'I really must be getting home; the night-air -doesn't suit my throat!' and a Canary called out in a trembling voice to -its children, 'Come away, my dears! It's high time you were all in bed!' -On various pretexts they all moved off, and Alice was soon left alone. - -'I wish I hadn't mentioned Dinah!' she said to herself in a melancholy -tone. 'Nobody seems to like her, down here, and I'm sure she's the best -cat in the world! Oh, my dear Dinah! I wonder if I shall ever see you -any more!' And here poor Alice began to cry again, for she felt very -lonely and low-spirited. In a little while, however, she again heard -a little pattering of footsteps in the distance, and she looked up -eagerly, half hoping that the Mouse had changed his mind, and was coming -back to finish his story. - - - - -CHAPTER 4. The Rabbit Sends in a Little Bill - -It was the White Rabbit, trotting slowly back again, and looking -anxiously about as it went, as if it had lost something; and she heard -it muttering to itself 'The Duchess! The Duchess! Oh my dear paws! Oh -my fur and whiskers! She'll get me executed, as sure as ferrets are -ferrets! Where CAN I have dropped them, I wonder?' Alice guessed in a -moment that it was looking for the fan and the pair of white kid gloves, -and she very good-naturedly began hunting about for them, but they were -nowhere to be seen--everything seemed to have changed since her swim in -the pool, and the great hall, with the glass table and the little door, -had vanished completely. - -Very soon the Rabbit noticed Alice, as she went hunting about, and -called out to her in an angry tone, 'Why, Mary Ann, what ARE you doing -out here? Run home this moment, and fetch me a pair of gloves and a fan! -Quick, now!' And Alice was so much frightened that she ran off at once -in the direction it pointed to, without trying to explain the mistake it -had made. - -'He took me for his housemaid,' she said to herself as she ran. 'How -surprised he'll be when he finds out who I am! But I'd better take him -his fan and gloves--that is, if I can find them.' As she said this, she -came upon a neat little house, on the door of which was a bright brass -plate with the name 'W. RABBIT' engraved upon it. She went in without -knocking, and hurried upstairs, in great fear lest she should meet the -real Mary Ann, and be turned out of the house before she had found the -fan and gloves. - -'How queer it seems,' Alice said to herself, 'to be going messages for -a rabbit! I suppose Dinah'll be sending me on messages next!' And she -began fancying the sort of thing that would happen: '"Miss Alice! Come -here directly, and get ready for your walk!" "Coming in a minute, -nurse! But I've got to see that the mouse doesn't get out." Only I don't -think,' Alice went on, 'that they'd let Dinah stop in the house if it -began ordering people about like that!' - -By this time she had found her way into a tidy little room with a table -in the window, and on it (as she had hoped) a fan and two or three pairs -of tiny white kid gloves: she took up the fan and a pair of the gloves, -and was just going to leave the room, when her eye fell upon a little -bottle that stood near the looking-glass. There was no label this time -with the words 'DRINK ME,' but nevertheless she uncorked it and put it -to her lips. 'I know SOMETHING interesting is sure to happen,' she said -to herself, 'whenever I eat or drink anything; so I'll just see what -this bottle does. I do hope it'll make me grow large again, for really -I'm quite tired of being such a tiny little thing!' - -It did so indeed, and much sooner than she had expected: before she had -drunk half the bottle, she found her head pressing against the ceiling, -and had to stoop to save her neck from being broken. She hastily put -down the bottle, saying to herself 'That's quite enough--I hope I shan't -grow any more--As it is, I can't get out at the door--I do wish I hadn't -drunk quite so much!' - -Alas! it was too late to wish that! She went on growing, and growing, -and very soon had to kneel down on the floor: in another minute there -was not even room for this, and she tried the effect of lying down with -one elbow against the door, and the other arm curled round her head. -Still she went on growing, and, as a last resource, she put one arm out -of the window, and one foot up the chimney, and said to herself 'Now I -can do no more, whatever happens. What WILL become of me?' - -Luckily for Alice, the little magic bottle had now had its full effect, -and she grew no larger: still it was very uncomfortable, and, as there -seemed to be no sort of chance of her ever getting out of the room -again, no wonder she felt unhappy. - -'It was much pleasanter at home,' thought poor Alice, 'when one wasn't -always growing larger and smaller, and being ordered about by mice and -rabbits. I almost wish I hadn't gone down that rabbit-hole--and yet--and -yet--it's rather curious, you know, this sort of life! I do wonder what -CAN have happened to me! When I used to read fairy-tales, I fancied that -kind of thing never happened, and now here I am in the middle of one! -There ought to be a book written about me, that there ought! And when I -grow up, I'll write one--but I'm grown up now,' she added in a sorrowful -tone; 'at least there's no room to grow up any more HERE.' - -'But then,' thought Alice, 'shall I NEVER get any older than I am -now? That'll be a comfort, one way--never to be an old woman--but -then--always to have lessons to learn! Oh, I shouldn't like THAT!' - -'Oh, you foolish Alice!' she answered herself. 'How can you learn -lessons in here? Why, there's hardly room for YOU, and no room at all -for any lesson-books!' - -And so she went on, taking first one side and then the other, and making -quite a conversation of it altogether; but after a few minutes she heard -a voice outside, and stopped to listen. - -'Mary Ann! Mary Ann!' said the voice. 'Fetch me my gloves this moment!' -Then came a little pattering of feet on the stairs. Alice knew it was -the Rabbit coming to look for her, and she trembled till she shook the -house, quite forgetting that she was now about a thousand times as large -as the Rabbit, and had no reason to be afraid of it. - -Presently the Rabbit came up to the door, and tried to open it; but, as -the door opened inwards, and Alice's elbow was pressed hard against it, -that attempt proved a failure. Alice heard it say to itself 'Then I'll -go round and get in at the window.' - -'THAT you won't' thought Alice, and, after waiting till she fancied -she heard the Rabbit just under the window, she suddenly spread out her -hand, and made a snatch in the air. She did not get hold of anything, -but she heard a little shriek and a fall, and a crash of broken glass, -from which she concluded that it was just possible it had fallen into a -cucumber-frame, or something of the sort. - -Next came an angry voice--the Rabbit's--'Pat! Pat! Where are you?' And -then a voice she had never heard before, 'Sure then I'm here! Digging -for apples, yer honour!' - -'Digging for apples, indeed!' said the Rabbit angrily. 'Here! Come and -help me out of THIS!' (Sounds of more broken glass.) - -'Now tell me, Pat, what's that in the window?' - -'Sure, it's an arm, yer honour!' (He pronounced it 'arrum.') - -'An arm, you goose! Who ever saw one that size? Why, it fills the whole -window!' - -'Sure, it does, yer honour: but it's an arm for all that.' - -'Well, it's got no business there, at any rate: go and take it away!' - -There was a long silence after this, and Alice could only hear whispers -now and then; such as, 'Sure, I don't like it, yer honour, at all, at -all!' 'Do as I tell you, you coward!' and at last she spread out her -hand again, and made another snatch in the air. This time there were -TWO little shrieks, and more sounds of broken glass. 'What a number of -cucumber-frames there must be!' thought Alice. 'I wonder what they'll do -next! As for pulling me out of the window, I only wish they COULD! I'm -sure I don't want to stay in here any longer!' - -She waited for some time without hearing anything more: at last came a -rumbling of little cartwheels, and the sound of a good many voices -all talking together: she made out the words: 'Where's the other -ladder?--Why, I hadn't to bring but one; Bill's got the other--Bill! -fetch it here, lad!--Here, put 'em up at this corner--No, tie 'em -together first--they don't reach half high enough yet--Oh! they'll -do well enough; don't be particular--Here, Bill! catch hold of this -rope--Will the roof bear?--Mind that loose slate--Oh, it's coming -down! Heads below!' (a loud crash)--'Now, who did that?--It was Bill, I -fancy--Who's to go down the chimney?--Nay, I shan't! YOU do it!--That I -won't, then!--Bill's to go down--Here, Bill! the master says you're to -go down the chimney!' - -'Oh! So Bill's got to come down the chimney, has he?' said Alice to -herself. 'Shy, they seem to put everything upon Bill! I wouldn't be in -Bill's place for a good deal: this fireplace is narrow, to be sure; but -I THINK I can kick a little!' - -She drew her foot as far down the chimney as she could, and waited -till she heard a little animal (she couldn't guess of what sort it was) -scratching and scrambling about in the chimney close above her: then, -saying to herself 'This is Bill,' she gave one sharp kick, and waited to -see what would happen next. - -The first thing she heard was a general chorus of 'There goes Bill!' -then the Rabbit's voice along--'Catch him, you by the hedge!' then -silence, and then another confusion of voices--'Hold up his head--Brandy -now--Don't choke him--How was it, old fellow? What happened to you? Tell -us all about it!' - -Last came a little feeble, squeaking voice, ('That's Bill,' thought -Alice,) 'Well, I hardly know--No more, thank ye; I'm better now--but I'm -a deal too flustered to tell you--all I know is, something comes at me -like a Jack-in-the-box, and up I goes like a sky-rocket!' - -'So you did, old fellow!' said the others. - -'We must burn the house down!' said the Rabbit's voice; and Alice called -out as loud as she could, 'If you do. I'll set Dinah at you!' - -There was a dead silence instantly, and Alice thought to herself, 'I -wonder what they WILL do next! If they had any sense, they'd take the -roof off.' After a minute or two, they began moving about again, and -Alice heard the Rabbit say, 'A barrowful will do, to begin with.' - -'A barrowful of WHAT?' thought Alice; but she had not long to doubt, -for the next moment a shower of little pebbles came rattling in at the -window, and some of them hit her in the face. 'I'll put a stop to this,' -she said to herself, and shouted out, 'You'd better not do that again!' -which produced another dead silence. - -Alice noticed with some surprise that the pebbles were all turning into -little cakes as they lay on the floor, and a bright idea came into her -head. 'If I eat one of these cakes,' she thought, 'it's sure to make -SOME change in my size; and as it can't possibly make me larger, it must -make me smaller, I suppose.' - -So she swallowed one of the cakes, and was delighted to find that she -began shrinking directly. As soon as she was small enough to get through -the door, she ran out of the house, and found quite a crowd of little -animals and birds waiting outside. The poor little Lizard, Bill, was -in the middle, being held up by two guinea-pigs, who were giving it -something out of a bottle. They all made a rush at Alice the moment she -appeared; but she ran off as hard as she could, and soon found herself -safe in a thick wood. - -'The first thing I've got to do,' said Alice to herself, as she wandered -about in the wood, 'is to grow to my right size again; and the second -thing is to find my way into that lovely garden. I think that will be -the best plan.' - -It sounded an excellent plan, no doubt, and very neatly and simply -arranged; the only difficulty was, that she had not the smallest idea -how to set about it; and while she was peering about anxiously among -the trees, a little sharp bark just over her head made her look up in a -great hurry. - -An enormous puppy was looking down at her with large round eyes, and -feebly stretching out one paw, trying to touch her. 'Poor little thing!' -said Alice, in a coaxing tone, and she tried hard to whistle to it; but -she was terribly frightened all the time at the thought that it might be -hungry, in which case it would be very likely to eat her up in spite of -all her coaxing. - -Hardly knowing what she did, she picked up a little bit of stick, and -held it out to the puppy; whereupon the puppy jumped into the air off -all its feet at once, with a yelp of delight, and rushed at the stick, -and made believe to worry it; then Alice dodged behind a great thistle, -to keep herself from being run over; and the moment she appeared on the -other side, the puppy made another rush at the stick, and tumbled head -over heels in its hurry to get hold of it; then Alice, thinking it was -very like having a game of play with a cart-horse, and expecting every -moment to be trampled under its feet, ran round the thistle again; then -the puppy began a series of short charges at the stick, running a very -little way forwards each time and a long way back, and barking hoarsely -all the while, till at last it sat down a good way off, panting, with -its tongue hanging out of its mouth, and its great eyes half shut. - -This seemed to Alice a good opportunity for making her escape; so she -set off at once, and ran till she was quite tired and out of breath, and -till the puppy's bark sounded quite faint in the distance. - -'And yet what a dear little puppy it was!' said Alice, as she leant -against a buttercup to rest herself, and fanned herself with one of the -leaves: 'I should have liked teaching it tricks very much, if--if I'd -only been the right size to do it! Oh dear! I'd nearly forgotten that -I've got to grow up again! Let me see--how IS it to be managed? I -suppose I ought to eat or drink something or other; but the great -question is, what?' - -The great question certainly was, what? Alice looked all round her at -the flowers and the blades of grass, but she did not see anything that -looked like the right thing to eat or drink under the circumstances. -There was a large mushroom growing near her, about the same height as -herself; and when she had looked under it, and on both sides of it, and -behind it, it occurred to her that she might as well look and see what -was on the top of it. - -She stretched herself up on tiptoe, and peeped over the edge of the -mushroom, and her eyes immediately met those of a large caterpillar, -that was sitting on the top with its arms folded, quietly smoking a long -hookah, and taking not the smallest notice of her or of anything else. - - - - -CHAPTER 5. Advice from a Caterpillar - -The Caterpillar and Alice looked at each other for some time in silence: -at last the Caterpillar took the hookah out of its mouth, and addressed -her in a languid, sleepy voice. - -'Who are YOU?' said the Caterpillar. - -This was not an encouraging opening for a conversation. Alice replied, -rather shyly, 'I--I hardly know, sir, just at present--at least I know -who I WAS when I got up this morning, but I think I must have been -changed several times since then.' - -'What do you mean by that?' said the Caterpillar sternly. 'Explain -yourself!' - -'I can't explain MYSELF, I'm afraid, sir' said Alice, 'because I'm not -myself, you see.' - -'I don't see,' said the Caterpillar. - -'I'm afraid I can't put it more clearly,' Alice replied very politely, -'for I can't understand it myself to begin with; and being so many -different sizes in a day is very confusing.' - -'It isn't,' said the Caterpillar. - -'Well, perhaps you haven't found it so yet,' said Alice; 'but when you -have to turn into a chrysalis--you will some day, you know--and then -after that into a butterfly, I should think you'll feel it a little -queer, won't you?' - -'Not a bit,' said the Caterpillar. - -'Well, perhaps your feelings may be different,' said Alice; 'all I know -is, it would feel very queer to ME.' - -'You!' said the Caterpillar contemptuously. 'Who are YOU?' - -Which brought them back again to the beginning of the conversation. -Alice felt a little irritated at the Caterpillar's making such VERY -short remarks, and she drew herself up and said, very gravely, 'I think, -you ought to tell me who YOU are, first.' - -'Why?' said the Caterpillar. - -Here was another puzzling question; and as Alice could not think of any -good reason, and as the Caterpillar seemed to be in a VERY unpleasant -state of mind, she turned away. - -'Come back!' the Caterpillar called after her. 'I've something important -to say!' - -This sounded promising, certainly: Alice turned and came back again. - -'Keep your temper,' said the Caterpillar. - -'Is that all?' said Alice, swallowing down her anger as well as she -could. - -'No,' said the Caterpillar. - -Alice thought she might as well wait, as she had nothing else to do, and -perhaps after all it might tell her something worth hearing. For some -minutes it puffed away without speaking, but at last it unfolded its -arms, took the hookah out of its mouth again, and said, 'So you think -you're changed, do you?' - -'I'm afraid I am, sir,' said Alice; 'I can't remember things as I -used--and I don't keep the same size for ten minutes together!' - -'Can't remember WHAT things?' said the Caterpillar. - -'Well, I've tried to say "HOW DOTH THE LITTLE BUSY BEE," but it all came -different!' Alice replied in a very melancholy voice. - -'Repeat, "YOU ARE OLD, FATHER WILLIAM,"' said the Caterpillar. - -Alice folded her hands, and began:-- - - 'You are old, Father William,' the young man said, - 'And your hair has become very white; - And yet you incessantly stand on your head-- - Do you think, at your age, it is right?' - - 'In my youth,' Father William replied to his son, - 'I feared it might injure the brain; - But, now that I'm perfectly sure I have none, - Why, I do it again and again.' - - 'You are old,' said the youth, 'as I mentioned before, - And have grown most uncommonly fat; - Yet you turned a back-somersault in at the door-- - Pray, what is the reason of that?' - - 'In my youth,' said the sage, as he shook his grey locks, - 'I kept all my limbs very supple - By the use of this ointment--one shilling the box-- - Allow me to sell you a couple?' - - 'You are old,' said the youth, 'and your jaws are too weak - For anything tougher than suet; - Yet you finished the goose, with the bones and the beak-- - Pray how did you manage to do it?' - - 'In my youth,' said his father, 'I took to the law, - And argued each case with my wife; - And the muscular strength, which it gave to my jaw, - Has lasted the rest of my life.' - - 'You are old,' said the youth, 'one would hardly suppose - That your eye was as steady as ever; - Yet you balanced an eel on the end of your nose-- - What made you so awfully clever?' - - 'I have answered three questions, and that is enough,' - Said his father; 'don't give yourself airs! - Do you think I can listen all day to such stuff? - Be off, or I'll kick you down stairs!' - - -'That is not said right,' said the Caterpillar. - -'Not QUITE right, I'm afraid,' said Alice, timidly; 'some of the words -have got altered.' - -'It is wrong from beginning to end,' said the Caterpillar decidedly, and -there was silence for some minutes. - -The Caterpillar was the first to speak. - -'What size do you want to be?' it asked. - -'Oh, I'm not particular as to size,' Alice hastily replied; 'only one -doesn't like changing so often, you know.' - -'I DON'T know,' said the Caterpillar. - -Alice said nothing: she had never been so much contradicted in her life -before, and she felt that she was losing her temper. - -'Are you content now?' said the Caterpillar. - -'Well, I should like to be a LITTLE larger, sir, if you wouldn't mind,' -said Alice: 'three inches is such a wretched height to be.' - -'It is a very good height indeed!' said the Caterpillar angrily, rearing -itself upright as it spoke (it was exactly three inches high). - -'But I'm not used to it!' pleaded poor Alice in a piteous tone. And -she thought of herself, 'I wish the creatures wouldn't be so easily -offended!' - -'You'll get used to it in time,' said the Caterpillar; and it put the -hookah into its mouth and began smoking again. - -This time Alice waited patiently until it chose to speak again. In -a minute or two the Caterpillar took the hookah out of its mouth -and yawned once or twice, and shook itself. Then it got down off the -mushroom, and crawled away in the grass, merely remarking as it went, -'One side will make you grow taller, and the other side will make you -grow shorter.' - -'One side of WHAT? The other side of WHAT?' thought Alice to herself. - -'Of the mushroom,' said the Caterpillar, just as if she had asked it -aloud; and in another moment it was out of sight. - -Alice remained looking thoughtfully at the mushroom for a minute, trying -to make out which were the two sides of it; and as it was perfectly -round, she found this a very difficult question. However, at last she -stretched her arms round it as far as they would go, and broke off a bit -of the edge with each hand. - -'And now which is which?' she said to herself, and nibbled a little of -the right-hand bit to try the effect: the next moment she felt a violent -blow underneath her chin: it had struck her foot! - -She was a good deal frightened by this very sudden change, but she felt -that there was no time to be lost, as she was shrinking rapidly; so she -set to work at once to eat some of the other bit. Her chin was pressed -so closely against her foot, that there was hardly room to open her -mouth; but she did it at last, and managed to swallow a morsel of the -lefthand bit. - - - * * * * * * * - - * * * * * * - - * * * * * * * - -'Come, my head's free at last!' said Alice in a tone of delight, which -changed into alarm in another moment, when she found that her shoulders -were nowhere to be found: all she could see, when she looked down, was -an immense length of neck, which seemed to rise like a stalk out of a -sea of green leaves that lay far below her. - -'What CAN all that green stuff be?' said Alice. 'And where HAVE my -shoulders got to? And oh, my poor hands, how is it I can't see you?' -She was moving them about as she spoke, but no result seemed to follow, -except a little shaking among the distant green leaves. - -As there seemed to be no chance of getting her hands up to her head, she -tried to get her head down to them, and was delighted to find that her -neck would bend about easily in any direction, like a serpent. She had -just succeeded in curving it down into a graceful zigzag, and was going -to dive in among the leaves, which she found to be nothing but the tops -of the trees under which she had been wandering, when a sharp hiss made -her draw back in a hurry: a large pigeon had flown into her face, and -was beating her violently with its wings. - -'Serpent!' screamed the Pigeon. - -'I'm NOT a serpent!' said Alice indignantly. 'Let me alone!' - -'Serpent, I say again!' repeated the Pigeon, but in a more subdued tone, -and added with a kind of sob, 'I've tried every way, and nothing seems -to suit them!' - -'I haven't the least idea what you're talking about,' said Alice. - -'I've tried the roots of trees, and I've tried banks, and I've tried -hedges,' the Pigeon went on, without attending to her; 'but those -serpents! There's no pleasing them!' - -Alice was more and more puzzled, but she thought there was no use in -saying anything more till the Pigeon had finished. - -'As if it wasn't trouble enough hatching the eggs,' said the Pigeon; -'but I must be on the look-out for serpents night and day! Why, I -haven't had a wink of sleep these three weeks!' - -'I'm very sorry you've been annoyed,' said Alice, who was beginning to -see its meaning. - -'And just as I'd taken the highest tree in the wood,' continued the -Pigeon, raising its voice to a shriek, 'and just as I was thinking I -should be free of them at last, they must needs come wriggling down from -the sky! Ugh, Serpent!' - -'But I'm NOT a serpent, I tell you!' said Alice. 'I'm a--I'm a--' - -'Well! WHAT are you?' said the Pigeon. 'I can see you're trying to -invent something!' - -'I--I'm a little girl,' said Alice, rather doubtfully, as she remembered -the number of changes she had gone through that day. - -'A likely story indeed!' said the Pigeon in a tone of the deepest -contempt. 'I've seen a good many little girls in my time, but never ONE -with such a neck as that! No, no! You're a serpent; and there's no use -denying it. I suppose you'll be telling me next that you never tasted an -egg!' - -'I HAVE tasted eggs, certainly,' said Alice, who was a very truthful -child; 'but little girls eat eggs quite as much as serpents do, you -know.' - -'I don't believe it,' said the Pigeon; 'but if they do, why then they're -a kind of serpent, that's all I can say.' - -This was such a new idea to Alice, that she was quite silent for a -minute or two, which gave the Pigeon the opportunity of adding, 'You're -looking for eggs, I know THAT well enough; and what does it matter to me -whether you're a little girl or a serpent?' - -'It matters a good deal to ME,' said Alice hastily; 'but I'm not looking -for eggs, as it happens; and if I was, I shouldn't want YOURS: I don't -like them raw.' - -'Well, be off, then!' said the Pigeon in a sulky tone, as it settled -down again into its nest. Alice crouched down among the trees as well as -she could, for her neck kept getting entangled among the branches, and -every now and then she had to stop and untwist it. After a while she -remembered that she still held the pieces of mushroom in her hands, and -she set to work very carefully, nibbling first at one and then at the -other, and growing sometimes taller and sometimes shorter, until she had -succeeded in bringing herself down to her usual height. - -It was so long since she had been anything near the right size, that it -felt quite strange at first; but she got used to it in a few minutes, -and began talking to herself, as usual. 'Come, there's half my plan done -now! How puzzling all these changes are! I'm never sure what I'm going -to be, from one minute to another! However, I've got back to my right -size: the next thing is, to get into that beautiful garden--how IS that -to be done, I wonder?' As she said this, she came suddenly upon an open -place, with a little house in it about four feet high. 'Whoever lives -there,' thought Alice, 'it'll never do to come upon them THIS size: why, -I should frighten them out of their wits!' So she began nibbling at the -righthand bit again, and did not venture to go near the house till she -had brought herself down to nine inches high. - - - - -CHAPTER 6. Pig and Pepper - -For a minute or two she stood looking at the house, and wondering what -to do next, when suddenly a footman in livery came running out of the -wood--(she considered him to be a footman because he was in livery: -otherwise, judging by his face only, she would have called him a -fish)--and rapped loudly at the door with his knuckles. It was opened -by another footman in livery, with a round face, and large eyes like a -frog; and both footmen, Alice noticed, had powdered hair that curled all -over their heads. She felt very curious to know what it was all about, -and crept a little way out of the wood to listen. - -The Fish-Footman began by producing from under his arm a great letter, -nearly as large as himself, and this he handed over to the other, -saying, in a solemn tone, 'For the Duchess. An invitation from the Queen -to play croquet.' The Frog-Footman repeated, in the same solemn tone, -only changing the order of the words a little, 'From the Queen. An -invitation for the Duchess to play croquet.' - -Then they both bowed low, and their curls got entangled together. - -Alice laughed so much at this, that she had to run back into the -wood for fear of their hearing her; and when she next peeped out the -Fish-Footman was gone, and the other was sitting on the ground near the -door, staring stupidly up into the sky. - -Alice went timidly up to the door, and knocked. - -'There's no sort of use in knocking,' said the Footman, 'and that for -two reasons. First, because I'm on the same side of the door as you -are; secondly, because they're making such a noise inside, no one could -possibly hear you.' And certainly there was a most extraordinary noise -going on within--a constant howling and sneezing, and every now and then -a great crash, as if a dish or kettle had been broken to pieces. - -'Please, then,' said Alice, 'how am I to get in?' - -'There might be some sense in your knocking,' the Footman went on -without attending to her, 'if we had the door between us. For instance, -if you were INSIDE, you might knock, and I could let you out, you know.' -He was looking up into the sky all the time he was speaking, and this -Alice thought decidedly uncivil. 'But perhaps he can't help it,' she -said to herself; 'his eyes are so VERY nearly at the top of his head. -But at any rate he might answer questions.--How am I to get in?' she -repeated, aloud. - -'I shall sit here,' the Footman remarked, 'till tomorrow--' - -At this moment the door of the house opened, and a large plate came -skimming out, straight at the Footman's head: it just grazed his nose, -and broke to pieces against one of the trees behind him. - -'--or next day, maybe,' the Footman continued in the same tone, exactly -as if nothing had happened. - -'How am I to get in?' asked Alice again, in a louder tone. - -'ARE you to get in at all?' said the Footman. 'That's the first -question, you know.' - -It was, no doubt: only Alice did not like to be told so. 'It's really -dreadful,' she muttered to herself, 'the way all the creatures argue. -It's enough to drive one crazy!' - -The Footman seemed to think this a good opportunity for repeating his -remark, with variations. 'I shall sit here,' he said, 'on and off, for -days and days.' - -'But what am I to do?' said Alice. - -'Anything you like,' said the Footman, and began whistling. - -'Oh, there's no use in talking to him,' said Alice desperately: 'he's -perfectly idiotic!' And she opened the door and went in. - -The door led right into a large kitchen, which was full of smoke from -one end to the other: the Duchess was sitting on a three-legged stool in -the middle, nursing a baby; the cook was leaning over the fire, stirring -a large cauldron which seemed to be full of soup. - -'There's certainly too much pepper in that soup!' Alice said to herself, -as well as she could for sneezing. - -There was certainly too much of it in the air. Even the Duchess -sneezed occasionally; and as for the baby, it was sneezing and howling -alternately without a moment's pause. The only things in the kitchen -that did not sneeze, were the cook, and a large cat which was sitting on -the hearth and grinning from ear to ear. - -'Please would you tell me,' said Alice, a little timidly, for she was -not quite sure whether it was good manners for her to speak first, 'why -your cat grins like that?' - -'It's a Cheshire cat,' said the Duchess, 'and that's why. Pig!' - -She said the last word with such sudden violence that Alice quite -jumped; but she saw in another moment that it was addressed to the baby, -and not to her, so she took courage, and went on again:-- - -'I didn't know that Cheshire cats always grinned; in fact, I didn't know -that cats COULD grin.' - -'They all can,' said the Duchess; 'and most of 'em do.' - -'I don't know of any that do,' Alice said very politely, feeling quite -pleased to have got into a conversation. - -'You don't know much,' said the Duchess; 'and that's a fact.' - -Alice did not at all like the tone of this remark, and thought it would -be as well to introduce some other subject of conversation. While she -was trying to fix on one, the cook took the cauldron of soup off the -fire, and at once set to work throwing everything within her reach at -the Duchess and the baby--the fire-irons came first; then followed a -shower of saucepans, plates, and dishes. The Duchess took no notice of -them even when they hit her; and the baby was howling so much already, -that it was quite impossible to say whether the blows hurt it or not. - -'Oh, PLEASE mind what you're doing!' cried Alice, jumping up and down in -an agony of terror. 'Oh, there goes his PRECIOUS nose'; as an unusually -large saucepan flew close by it, and very nearly carried it off. - -'If everybody minded their own business,' the Duchess said in a hoarse -growl, 'the world would go round a deal faster than it does.' - -'Which would NOT be an advantage,' said Alice, who felt very glad to get -an opportunity of showing off a little of her knowledge. 'Just think of -what work it would make with the day and night! You see the earth takes -twenty-four hours to turn round on its axis--' - -'Talking of axes,' said the Duchess, 'chop off her head!' - -Alice glanced rather anxiously at the cook, to see if she meant to take -the hint; but the cook was busily stirring the soup, and seemed not to -be listening, so she went on again: 'Twenty-four hours, I THINK; or is -it twelve? I--' - -'Oh, don't bother ME,' said the Duchess; 'I never could abide figures!' -And with that she began nursing her child again, singing a sort of -lullaby to it as she did so, and giving it a violent shake at the end of -every line: - - 'Speak roughly to your little boy, - And beat him when he sneezes: - He only does it to annoy, - Because he knows it teases.' - - CHORUS. - - (In which the cook and the baby joined):-- - - 'Wow! wow! wow!' - -While the Duchess sang the second verse of the song, she kept tossing -the baby violently up and down, and the poor little thing howled so, -that Alice could hardly hear the words:-- - - 'I speak severely to my boy, - I beat him when he sneezes; - For he can thoroughly enjoy - The pepper when he pleases!' - - CHORUS. - - 'Wow! wow! wow!' - -'Here! you may nurse it a bit, if you like!' the Duchess said to Alice, -flinging the baby at her as she spoke. 'I must go and get ready to play -croquet with the Queen,' and she hurried out of the room. The cook threw -a frying-pan after her as she went out, but it just missed her. - -Alice caught the baby with some difficulty, as it was a queer-shaped -little creature, and held out its arms and legs in all directions, 'just -like a star-fish,' thought Alice. The poor little thing was snorting -like a steam-engine when she caught it, and kept doubling itself up and -straightening itself out again, so that altogether, for the first minute -or two, it was as much as she could do to hold it. - -As soon as she had made out the proper way of nursing it, (which was to -twist it up into a sort of knot, and then keep tight hold of its right -ear and left foot, so as to prevent its undoing itself,) she carried -it out into the open air. 'IF I don't take this child away with me,' -thought Alice, 'they're sure to kill it in a day or two: wouldn't it be -murder to leave it behind?' She said the last words out loud, and the -little thing grunted in reply (it had left off sneezing by this time). -'Don't grunt,' said Alice; 'that's not at all a proper way of expressing -yourself.' - -The baby grunted again, and Alice looked very anxiously into its face to -see what was the matter with it. There could be no doubt that it had -a VERY turn-up nose, much more like a snout than a real nose; also its -eyes were getting extremely small for a baby: altogether Alice did not -like the look of the thing at all. 'But perhaps it was only sobbing,' -she thought, and looked into its eyes again, to see if there were any -tears. - -No, there were no tears. 'If you're going to turn into a pig, my dear,' -said Alice, seriously, 'I'll have nothing more to do with you. Mind -now!' The poor little thing sobbed again (or grunted, it was impossible -to say which), and they went on for some while in silence. - -Alice was just beginning to think to herself, 'Now, what am I to do with -this creature when I get it home?' when it grunted again, so violently, -that she looked down into its face in some alarm. This time there could -be NO mistake about it: it was neither more nor less than a pig, and she -felt that it would be quite absurd for her to carry it further. - -So she set the little creature down, and felt quite relieved to see -it trot away quietly into the wood. 'If it had grown up,' she said -to herself, 'it would have made a dreadfully ugly child: but it makes -rather a handsome pig, I think.' And she began thinking over other -children she knew, who might do very well as pigs, and was just saying -to herself, 'if one only knew the right way to change them--' when she -was a little startled by seeing the Cheshire Cat sitting on a bough of a -tree a few yards off. - -The Cat only grinned when it saw Alice. It looked good-natured, she -thought: still it had VERY long claws and a great many teeth, so she -felt that it ought to be treated with respect. - -'Cheshire Puss,' she began, rather timidly, as she did not at all know -whether it would like the name: however, it only grinned a little wider. -'Come, it's pleased so far,' thought Alice, and she went on. 'Would you -tell me, please, which way I ought to go from here?' - -'That depends a good deal on where you want to get to,' said the Cat. - -'I don't much care where--' said Alice. - -'Then it doesn't matter which way you go,' said the Cat. - -'--so long as I get SOMEWHERE,' Alice added as an explanation. - -'Oh, you're sure to do that,' said the Cat, 'if you only walk long -enough.' - -Alice felt that this could not be denied, so she tried another question. -'What sort of people live about here?' - -'In THAT direction,' the Cat said, waving its right paw round, 'lives -a Hatter: and in THAT direction,' waving the other paw, 'lives a March -Hare. Visit either you like: they're both mad.' - -'But I don't want to go among mad people,' Alice remarked. - -'Oh, you can't help that,' said the Cat: 'we're all mad here. I'm mad. -You're mad.' - -'How do you know I'm mad?' said Alice. - -'You must be,' said the Cat, 'or you wouldn't have come here.' - -Alice didn't think that proved it at all; however, she went on 'And how -do you know that you're mad?' - -'To begin with,' said the Cat, 'a dog's not mad. You grant that?' - -'I suppose so,' said Alice. - -'Well, then,' the Cat went on, 'you see, a dog growls when it's angry, -and wags its tail when it's pleased. Now I growl when I'm pleased, and -wag my tail when I'm angry. Therefore I'm mad.' - -'I call it purring, not growling,' said Alice. - -'Call it what you like,' said the Cat. 'Do you play croquet with the -Queen to-day?' - -'I should like it very much,' said Alice, 'but I haven't been invited -yet.' - -'You'll see me there,' said the Cat, and vanished. - -Alice was not much surprised at this, she was getting so used to queer -things happening. While she was looking at the place where it had been, -it suddenly appeared again. - -'By-the-bye, what became of the baby?' said the Cat. 'I'd nearly -forgotten to ask.' - -'It turned into a pig,' Alice quietly said, just as if it had come back -in a natural way. - -'I thought it would,' said the Cat, and vanished again. - -Alice waited a little, half expecting to see it again, but it did not -appear, and after a minute or two she walked on in the direction in -which the March Hare was said to live. 'I've seen hatters before,' she -said to herself; 'the March Hare will be much the most interesting, and -perhaps as this is May it won't be raving mad--at least not so mad as -it was in March.' As she said this, she looked up, and there was the Cat -again, sitting on a branch of a tree. - -'Did you say pig, or fig?' said the Cat. - -'I said pig,' replied Alice; 'and I wish you wouldn't keep appearing and -vanishing so suddenly: you make one quite giddy.' - -'All right,' said the Cat; and this time it vanished quite slowly, -beginning with the end of the tail, and ending with the grin, which -remained some time after the rest of it had gone. - -'Well! I've often seen a cat without a grin,' thought Alice; 'but a grin -without a cat! It's the most curious thing I ever saw in my life!' - -She had not gone much farther before she came in sight of the house -of the March Hare: she thought it must be the right house, because the -chimneys were shaped like ears and the roof was thatched with fur. It -was so large a house, that she did not like to go nearer till she had -nibbled some more of the lefthand bit of mushroom, and raised herself to -about two feet high: even then she walked up towards it rather timidly, -saying to herself 'Suppose it should be raving mad after all! I almost -wish I'd gone to see the Hatter instead!' - - - - -CHAPTER 7. A Mad Tea-Party - -There was a table set out under a tree in front of the house, and the -March Hare and the Hatter were having tea at it: a Dormouse was sitting -between them, fast asleep, and the other two were using it as a -cushion, resting their elbows on it, and talking over its head. 'Very -uncomfortable for the Dormouse,' thought Alice; 'only, as it's asleep, I -suppose it doesn't mind.' - -The table was a large one, but the three were all crowded together at -one corner of it: 'No room! No room!' they cried out when they saw Alice -coming. 'There's PLENTY of room!' said Alice indignantly, and she sat -down in a large arm-chair at one end of the table. - -'Have some wine,' the March Hare said in an encouraging tone. - -Alice looked all round the table, but there was nothing on it but tea. -'I don't see any wine,' she remarked. - -'There isn't any,' said the March Hare. - -'Then it wasn't very civil of you to offer it,' said Alice angrily. - -'It wasn't very civil of you to sit down without being invited,' said -the March Hare. - -'I didn't know it was YOUR table,' said Alice; 'it's laid for a great -many more than three.' - -'Your hair wants cutting,' said the Hatter. He had been looking at Alice -for some time with great curiosity, and this was his first speech. - -'You should learn not to make personal remarks,' Alice said with some -severity; 'it's very rude.' - -The Hatter opened his eyes very wide on hearing this; but all he SAID -was, 'Why is a raven like a writing-desk?' - -'Come, we shall have some fun now!' thought Alice. 'I'm glad they've -begun asking riddles.--I believe I can guess that,' she added aloud. - -'Do you mean that you think you can find out the answer to it?' said the -March Hare. - -'Exactly so,' said Alice. - -'Then you should say what you mean,' the March Hare went on. - -'I do,' Alice hastily replied; 'at least--at least I mean what I -say--that's the same thing, you know.' - -'Not the same thing a bit!' said the Hatter. 'You might just as well say -that "I see what I eat" is the same thing as "I eat what I see"!' - -'You might just as well say,' added the March Hare, 'that "I like what I -get" is the same thing as "I get what I like"!' - -'You might just as well say,' added the Dormouse, who seemed to be -talking in his sleep, 'that "I breathe when I sleep" is the same thing -as "I sleep when I breathe"!' - -'It IS the same thing with you,' said the Hatter, and here the -conversation dropped, and the party sat silent for a minute, while Alice -thought over all she could remember about ravens and writing-desks, -which wasn't much. - -The Hatter was the first to break the silence. 'What day of the month -is it?' he said, turning to Alice: he had taken his watch out of his -pocket, and was looking at it uneasily, shaking it every now and then, -and holding it to his ear. - -Alice considered a little, and then said 'The fourth.' - -'Two days wrong!' sighed the Hatter. 'I told you butter wouldn't suit -the works!' he added looking angrily at the March Hare. - -'It was the BEST butter,' the March Hare meekly replied. - -'Yes, but some crumbs must have got in as well,' the Hatter grumbled: -'you shouldn't have put it in with the bread-knife.' - -The March Hare took the watch and looked at it gloomily: then he dipped -it into his cup of tea, and looked at it again: but he could think of -nothing better to say than his first remark, 'It was the BEST butter, -you know.' - -Alice had been looking over his shoulder with some curiosity. 'What a -funny watch!' she remarked. 'It tells the day of the month, and doesn't -tell what o'clock it is!' - -'Why should it?' muttered the Hatter. 'Does YOUR watch tell you what -year it is?' - -'Of course not,' Alice replied very readily: 'but that's because it -stays the same year for such a long time together.' - -'Which is just the case with MINE,' said the Hatter. - -Alice felt dreadfully puzzled. The Hatter's remark seemed to have no -sort of meaning in it, and yet it was certainly English. 'I don't quite -understand you,' she said, as politely as she could. - -'The Dormouse is asleep again,' said the Hatter, and he poured a little -hot tea upon its nose. - -The Dormouse shook its head impatiently, and said, without opening its -eyes, 'Of course, of course; just what I was going to remark myself.' - -'Have you guessed the riddle yet?' the Hatter said, turning to Alice -again. - -'No, I give it up,' Alice replied: 'what's the answer?' - -'I haven't the slightest idea,' said the Hatter. - -'Nor I,' said the March Hare. - -Alice sighed wearily. 'I think you might do something better with the -time,' she said, 'than waste it in asking riddles that have no answers.' - -'If you knew Time as well as I do,' said the Hatter, 'you wouldn't talk -about wasting IT. It's HIM.' - -'I don't know what you mean,' said Alice. - -'Of course you don't!' the Hatter said, tossing his head contemptuously. -'I dare say you never even spoke to Time!' - -'Perhaps not,' Alice cautiously replied: 'but I know I have to beat time -when I learn music.' - -'Ah! that accounts for it,' said the Hatter. 'He won't stand beating. -Now, if you only kept on good terms with him, he'd do almost anything -you liked with the clock. For instance, suppose it were nine o'clock in -the morning, just time to begin lessons: you'd only have to whisper a -hint to Time, and round goes the clock in a twinkling! Half-past one, -time for dinner!' - -('I only wish it was,' the March Hare said to itself in a whisper.) - -'That would be grand, certainly,' said Alice thoughtfully: 'but then--I -shouldn't be hungry for it, you know.' - -'Not at first, perhaps,' said the Hatter: 'but you could keep it to -half-past one as long as you liked.' - -'Is that the way YOU manage?' Alice asked. - -The Hatter shook his head mournfully. 'Not I!' he replied. 'We -quarrelled last March--just before HE went mad, you know--' (pointing -with his tea spoon at the March Hare,) '--it was at the great concert -given by the Queen of Hearts, and I had to sing - - "Twinkle, twinkle, little bat! - How I wonder what you're at!" - -You know the song, perhaps?' - -'I've heard something like it,' said Alice. - -'It goes on, you know,' the Hatter continued, 'in this way:-- - - "Up above the world you fly, - Like a tea-tray in the sky. - Twinkle, twinkle--"' - -Here the Dormouse shook itself, and began singing in its sleep 'Twinkle, -twinkle, twinkle, twinkle--' and went on so long that they had to pinch -it to make it stop. - -'Well, I'd hardly finished the first verse,' said the Hatter, 'when the -Queen jumped up and bawled out, "He's murdering the time! Off with his -head!"' - -'How dreadfully savage!' exclaimed Alice. - -'And ever since that,' the Hatter went on in a mournful tone, 'he won't -do a thing I ask! It's always six o'clock now.' - -A bright idea came into Alice's head. 'Is that the reason so many -tea-things are put out here?' she asked. - -'Yes, that's it,' said the Hatter with a sigh: 'it's always tea-time, -and we've no time to wash the things between whiles.' - -'Then you keep moving round, I suppose?' said Alice. - -'Exactly so,' said the Hatter: 'as the things get used up.' - -'But what happens when you come to the beginning again?' Alice ventured -to ask. - -'Suppose we change the subject,' the March Hare interrupted, yawning. -'I'm getting tired of this. I vote the young lady tells us a story.' - -'I'm afraid I don't know one,' said Alice, rather alarmed at the -proposal. - -'Then the Dormouse shall!' they both cried. 'Wake up, Dormouse!' And -they pinched it on both sides at once. - -The Dormouse slowly opened his eyes. 'I wasn't asleep,' he said in a -hoarse, feeble voice: 'I heard every word you fellows were saying.' - -'Tell us a story!' said the March Hare. - -'Yes, please do!' pleaded Alice. - -'And be quick about it,' added the Hatter, 'or you'll be asleep again -before it's done.' - -'Once upon a time there were three little sisters,' the Dormouse began -in a great hurry; 'and their names were Elsie, Lacie, and Tillie; and -they lived at the bottom of a well--' - -'What did they live on?' said Alice, who always took a great interest in -questions of eating and drinking. - -'They lived on treacle,' said the Dormouse, after thinking a minute or -two. - -'They couldn't have done that, you know,' Alice gently remarked; 'they'd -have been ill.' - -'So they were,' said the Dormouse; 'VERY ill.' - -Alice tried to fancy to herself what such an extraordinary ways of -living would be like, but it puzzled her too much, so she went on: 'But -why did they live at the bottom of a well?' - -'Take some more tea,' the March Hare said to Alice, very earnestly. - -'I've had nothing yet,' Alice replied in an offended tone, 'so I can't -take more.' - -'You mean you can't take LESS,' said the Hatter: 'it's very easy to take -MORE than nothing.' - -'Nobody asked YOUR opinion,' said Alice. - -'Who's making personal remarks now?' the Hatter asked triumphantly. - -Alice did not quite know what to say to this: so she helped herself -to some tea and bread-and-butter, and then turned to the Dormouse, and -repeated her question. 'Why did they live at the bottom of a well?' - -The Dormouse again took a minute or two to think about it, and then -said, 'It was a treacle-well.' - -'There's no such thing!' Alice was beginning very angrily, but the -Hatter and the March Hare went 'Sh! sh!' and the Dormouse sulkily -remarked, 'If you can't be civil, you'd better finish the story for -yourself.' - -'No, please go on!' Alice said very humbly; 'I won't interrupt again. I -dare say there may be ONE.' - -'One, indeed!' said the Dormouse indignantly. However, he consented to -go on. 'And so these three little sisters--they were learning to draw, -you know--' - -'What did they draw?' said Alice, quite forgetting her promise. - -'Treacle,' said the Dormouse, without considering at all this time. - -'I want a clean cup,' interrupted the Hatter: 'let's all move one place -on.' - -He moved on as he spoke, and the Dormouse followed him: the March Hare -moved into the Dormouse's place, and Alice rather unwillingly took -the place of the March Hare. The Hatter was the only one who got any -advantage from the change: and Alice was a good deal worse off than -before, as the March Hare had just upset the milk-jug into his plate. - -Alice did not wish to offend the Dormouse again, so she began very -cautiously: 'But I don't understand. Where did they draw the treacle -from?' - -'You can draw water out of a water-well,' said the Hatter; 'so I should -think you could draw treacle out of a treacle-well--eh, stupid?' - -'But they were IN the well,' Alice said to the Dormouse, not choosing to -notice this last remark. - -'Of course they were', said the Dormouse; '--well in.' - -This answer so confused poor Alice, that she let the Dormouse go on for -some time without interrupting it. - -'They were learning to draw,' the Dormouse went on, yawning and rubbing -its eyes, for it was getting very sleepy; 'and they drew all manner of -things--everything that begins with an M--' - -'Why with an M?' said Alice. - -'Why not?' said the March Hare. - -Alice was silent. - -The Dormouse had closed its eyes by this time, and was going off into -a doze; but, on being pinched by the Hatter, it woke up again with -a little shriek, and went on: '--that begins with an M, such as -mouse-traps, and the moon, and memory, and muchness--you know you say -things are "much of a muchness"--did you ever see such a thing as a -drawing of a muchness?' - -'Really, now you ask me,' said Alice, very much confused, 'I don't -think--' - -'Then you shouldn't talk,' said the Hatter. - -This piece of rudeness was more than Alice could bear: she got up in -great disgust, and walked off; the Dormouse fell asleep instantly, and -neither of the others took the least notice of her going, though she -looked back once or twice, half hoping that they would call after her: -the last time she saw them, they were trying to put the Dormouse into -the teapot. - -'At any rate I'll never go THERE again!' said Alice as she picked her -way through the wood. 'It's the stupidest tea-party I ever was at in all -my life!' - -Just as she said this, she noticed that one of the trees had a door -leading right into it. 'That's very curious!' she thought. 'But -everything's curious today. I think I may as well go in at once.' And in -she went. - -Once more she found herself in the long hall, and close to the little -glass table. 'Now, I'll manage better this time,' she said to herself, -and began by taking the little golden key, and unlocking the door that -led into the garden. Then she went to work nibbling at the mushroom (she -had kept a piece of it in her pocket) till she was about a foot high: -then she walked down the little passage: and THEN--she found herself at -last in the beautiful garden, among the bright flower-beds and the cool -fountains. - - - - -CHAPTER 8. The Queen's Croquet-Ground - -A large rose-tree stood near the entrance of the garden: the roses -growing on it were white, but there were three gardeners at it, busily -painting them red. Alice thought this a very curious thing, and she went -nearer to watch them, and just as she came up to them she heard one of -them say, 'Look out now, Five! Don't go splashing paint over me like -that!' - -'I couldn't help it,' said Five, in a sulky tone; 'Seven jogged my -elbow.' - -On which Seven looked up and said, 'That's right, Five! Always lay the -blame on others!' - -'YOU'D better not talk!' said Five. 'I heard the Queen say only -yesterday you deserved to be beheaded!' - -'What for?' said the one who had spoken first. - -'That's none of YOUR business, Two!' said Seven. - -'Yes, it IS his business!' said Five, 'and I'll tell him--it was for -bringing the cook tulip-roots instead of onions.' - -Seven flung down his brush, and had just begun 'Well, of all the unjust -things--' when his eye chanced to fall upon Alice, as she stood watching -them, and he checked himself suddenly: the others looked round also, and -all of them bowed low. - -'Would you tell me,' said Alice, a little timidly, 'why you are painting -those roses?' - -Five and Seven said nothing, but looked at Two. Two began in a low -voice, 'Why the fact is, you see, Miss, this here ought to have been a -RED rose-tree, and we put a white one in by mistake; and if the Queen -was to find it out, we should all have our heads cut off, you know. -So you see, Miss, we're doing our best, afore she comes, to--' At this -moment Five, who had been anxiously looking across the garden, called -out 'The Queen! The Queen!' and the three gardeners instantly threw -themselves flat upon their faces. There was a sound of many footsteps, -and Alice looked round, eager to see the Queen. - -First came ten soldiers carrying clubs; these were all shaped like -the three gardeners, oblong and flat, with their hands and feet at the -corners: next the ten courtiers; these were ornamented all over with -diamonds, and walked two and two, as the soldiers did. After these came -the royal children; there were ten of them, and the little dears came -jumping merrily along hand in hand, in couples: they were all ornamented -with hearts. Next came the guests, mostly Kings and Queens, and among -them Alice recognised the White Rabbit: it was talking in a hurried -nervous manner, smiling at everything that was said, and went by without -noticing her. Then followed the Knave of Hearts, carrying the King's -crown on a crimson velvet cushion; and, last of all this grand -procession, came THE KING AND QUEEN OF HEARTS. - -Alice was rather doubtful whether she ought not to lie down on her face -like the three gardeners, but she could not remember ever having heard -of such a rule at processions; 'and besides, what would be the use of -a procession,' thought she, 'if people had all to lie down upon their -faces, so that they couldn't see it?' So she stood still where she was, -and waited. - -When the procession came opposite to Alice, they all stopped and looked -at her, and the Queen said severely 'Who is this?' She said it to the -Knave of Hearts, who only bowed and smiled in reply. - -'Idiot!' said the Queen, tossing her head impatiently; and, turning to -Alice, she went on, 'What's your name, child?' - -'My name is Alice, so please your Majesty,' said Alice very politely; -but she added, to herself, 'Why, they're only a pack of cards, after -all. I needn't be afraid of them!' - -'And who are THESE?' said the Queen, pointing to the three gardeners who -were lying round the rosetree; for, you see, as they were lying on their -faces, and the pattern on their backs was the same as the rest of the -pack, she could not tell whether they were gardeners, or soldiers, or -courtiers, or three of her own children. - -'How should I know?' said Alice, surprised at her own courage. 'It's no -business of MINE.' - -The Queen turned crimson with fury, and, after glaring at her for a -moment like a wild beast, screamed 'Off with her head! Off--' - -'Nonsense!' said Alice, very loudly and decidedly, and the Queen was -silent. - -The King laid his hand upon her arm, and timidly said 'Consider, my -dear: she is only a child!' - -The Queen turned angrily away from him, and said to the Knave 'Turn them -over!' - -The Knave did so, very carefully, with one foot. - -'Get up!' said the Queen, in a shrill, loud voice, and the three -gardeners instantly jumped up, and began bowing to the King, the Queen, -the royal children, and everybody else. - -'Leave off that!' screamed the Queen. 'You make me giddy.' And then, -turning to the rose-tree, she went on, 'What HAVE you been doing here?' - -'May it please your Majesty,' said Two, in a very humble tone, going -down on one knee as he spoke, 'we were trying--' - -'I see!' said the Queen, who had meanwhile been examining the roses. -'Off with their heads!' and the procession moved on, three of the -soldiers remaining behind to execute the unfortunate gardeners, who ran -to Alice for protection. - -'You shan't be beheaded!' said Alice, and she put them into a large -flower-pot that stood near. The three soldiers wandered about for a -minute or two, looking for them, and then quietly marched off after the -others. - -'Are their heads off?' shouted the Queen. - -'Their heads are gone, if it please your Majesty!' the soldiers shouted -in reply. - -'That's right!' shouted the Queen. 'Can you play croquet?' - -The soldiers were silent, and looked at Alice, as the question was -evidently meant for her. - -'Yes!' shouted Alice. - -'Come on, then!' roared the Queen, and Alice joined the procession, -wondering very much what would happen next. - -'It's--it's a very fine day!' said a timid voice at her side. She was -walking by the White Rabbit, who was peeping anxiously into her face. - -'Very,' said Alice: '--where's the Duchess?' - -'Hush! Hush!' said the Rabbit in a low, hurried tone. He looked -anxiously over his shoulder as he spoke, and then raised himself upon -tiptoe, put his mouth close to her ear, and whispered 'She's under -sentence of execution.' - -'What for?' said Alice. - -'Did you say "What a pity!"?' the Rabbit asked. - -'No, I didn't,' said Alice: 'I don't think it's at all a pity. I said -"What for?"' - -'She boxed the Queen's ears--' the Rabbit began. Alice gave a little -scream of laughter. 'Oh, hush!' the Rabbit whispered in a frightened -tone. 'The Queen will hear you! You see, she came rather late, and the -Queen said--' - -'Get to your places!' shouted the Queen in a voice of thunder, and -people began running about in all directions, tumbling up against each -other; however, they got settled down in a minute or two, and the game -began. Alice thought she had never seen such a curious croquet-ground in -her life; it was all ridges and furrows; the balls were live hedgehogs, -the mallets live flamingoes, and the soldiers had to double themselves -up and to stand on their hands and feet, to make the arches. - -The chief difficulty Alice found at first was in managing her flamingo: -she succeeded in getting its body tucked away, comfortably enough, under -her arm, with its legs hanging down, but generally, just as she had got -its neck nicely straightened out, and was going to give the hedgehog a -blow with its head, it WOULD twist itself round and look up in her face, -with such a puzzled expression that she could not help bursting out -laughing: and when she had got its head down, and was going to begin -again, it was very provoking to find that the hedgehog had unrolled -itself, and was in the act of crawling away: besides all this, there was -generally a ridge or furrow in the way wherever she wanted to send the -hedgehog to, and, as the doubled-up soldiers were always getting up -and walking off to other parts of the ground, Alice soon came to the -conclusion that it was a very difficult game indeed. - -The players all played at once without waiting for turns, quarrelling -all the while, and fighting for the hedgehogs; and in a very short -time the Queen was in a furious passion, and went stamping about, and -shouting 'Off with his head!' or 'Off with her head!' about once in a -minute. - -Alice began to feel very uneasy: to be sure, she had not as yet had any -dispute with the Queen, but she knew that it might happen any minute, -'and then,' thought she, 'what would become of me? They're dreadfully -fond of beheading people here; the great wonder is, that there's any one -left alive!' - -She was looking about for some way of escape, and wondering whether she -could get away without being seen, when she noticed a curious appearance -in the air: it puzzled her very much at first, but, after watching it -a minute or two, she made it out to be a grin, and she said to herself -'It's the Cheshire Cat: now I shall have somebody to talk to.' - -'How are you getting on?' said the Cat, as soon as there was mouth -enough for it to speak with. - -Alice waited till the eyes appeared, and then nodded. 'It's no use -speaking to it,' she thought, 'till its ears have come, or at least one -of them.' In another minute the whole head appeared, and then Alice put -down her flamingo, and began an account of the game, feeling very glad -she had someone to listen to her. The Cat seemed to think that there was -enough of it now in sight, and no more of it appeared. - -'I don't think they play at all fairly,' Alice began, in rather a -complaining tone, 'and they all quarrel so dreadfully one can't hear -oneself speak--and they don't seem to have any rules in particular; -at least, if there are, nobody attends to them--and you've no idea how -confusing it is all the things being alive; for instance, there's the -arch I've got to go through next walking about at the other end of the -ground--and I should have croqueted the Queen's hedgehog just now, only -it ran away when it saw mine coming!' - -'How do you like the Queen?' said the Cat in a low voice. - -'Not at all,' said Alice: 'she's so extremely--' Just then she noticed -that the Queen was close behind her, listening: so she went on, -'--likely to win, that it's hardly worth while finishing the game.' - -The Queen smiled and passed on. - -'Who ARE you talking to?' said the King, going up to Alice, and looking -at the Cat's head with great curiosity. - -'It's a friend of mine--a Cheshire Cat,' said Alice: 'allow me to -introduce it.' - -'I don't like the look of it at all,' said the King: 'however, it may -kiss my hand if it likes.' - -'I'd rather not,' the Cat remarked. - -'Don't be impertinent,' said the King, 'and don't look at me like that!' -He got behind Alice as he spoke. - -'A cat may look at a king,' said Alice. 'I've read that in some book, -but I don't remember where.' - -'Well, it must be removed,' said the King very decidedly, and he called -the Queen, who was passing at the moment, 'My dear! I wish you would -have this cat removed!' - -The Queen had only one way of settling all difficulties, great or small. -'Off with his head!' she said, without even looking round. - -'I'll fetch the executioner myself,' said the King eagerly, and he -hurried off. - -Alice thought she might as well go back, and see how the game was going -on, as she heard the Queen's voice in the distance, screaming with -passion. She had already heard her sentence three of the players to be -executed for having missed their turns, and she did not like the look -of things at all, as the game was in such confusion that she never knew -whether it was her turn or not. So she went in search of her hedgehog. - -The hedgehog was engaged in a fight with another hedgehog, which seemed -to Alice an excellent opportunity for croqueting one of them with the -other: the only difficulty was, that her flamingo was gone across to the -other side of the garden, where Alice could see it trying in a helpless -sort of way to fly up into a tree. - -By the time she had caught the flamingo and brought it back, the fight -was over, and both the hedgehogs were out of sight: 'but it doesn't -matter much,' thought Alice, 'as all the arches are gone from this side -of the ground.' So she tucked it away under her arm, that it might not -escape again, and went back for a little more conversation with her -friend. - -When she got back to the Cheshire Cat, she was surprised to find quite a -large crowd collected round it: there was a dispute going on between -the executioner, the King, and the Queen, who were all talking at once, -while all the rest were quite silent, and looked very uncomfortable. - -The moment Alice appeared, she was appealed to by all three to settle -the question, and they repeated their arguments to her, though, as they -all spoke at once, she found it very hard indeed to make out exactly -what they said. - -The executioner's argument was, that you couldn't cut off a head unless -there was a body to cut it off from: that he had never had to do such a -thing before, and he wasn't going to begin at HIS time of life. - -The King's argument was, that anything that had a head could be -beheaded, and that you weren't to talk nonsense. - -The Queen's argument was, that if something wasn't done about it in less -than no time she'd have everybody executed, all round. (It was this last -remark that had made the whole party look so grave and anxious.) - -Alice could think of nothing else to say but 'It belongs to the Duchess: -you'd better ask HER about it.' - -'She's in prison,' the Queen said to the executioner: 'fetch her here.' -And the executioner went off like an arrow. - - The Cat's head began fading away the moment he was gone, and, -by the time he had come back with the Duchess, it had entirely -disappeared; so the King and the executioner ran wildly up and down -looking for it, while the rest of the party went back to the game. - - - - -CHAPTER 9. The Mock Turtle's Story - -'You can't think how glad I am to see you again, you dear old thing!' -said the Duchess, as she tucked her arm affectionately into Alice's, and -they walked off together. - -Alice was very glad to find her in such a pleasant temper, and thought -to herself that perhaps it was only the pepper that had made her so -savage when they met in the kitchen. - -'When I'M a Duchess,' she said to herself, (not in a very hopeful tone -though), 'I won't have any pepper in my kitchen AT ALL. Soup does very -well without--Maybe it's always pepper that makes people hot-tempered,' -she went on, very much pleased at having found out a new kind of -rule, 'and vinegar that makes them sour--and camomile that makes -them bitter--and--and barley-sugar and such things that make children -sweet-tempered. I only wish people knew that: then they wouldn't be so -stingy about it, you know--' - -She had quite forgotten the Duchess by this time, and was a little -startled when she heard her voice close to her ear. 'You're thinking -about something, my dear, and that makes you forget to talk. I can't -tell you just now what the moral of that is, but I shall remember it in -a bit.' - -'Perhaps it hasn't one,' Alice ventured to remark. - -'Tut, tut, child!' said the Duchess. 'Everything's got a moral, if only -you can find it.' And she squeezed herself up closer to Alice's side as -she spoke. - -Alice did not much like keeping so close to her: first, because the -Duchess was VERY ugly; and secondly, because she was exactly the -right height to rest her chin upon Alice's shoulder, and it was an -uncomfortably sharp chin. However, she did not like to be rude, so she -bore it as well as she could. - -'The game's going on rather better now,' she said, by way of keeping up -the conversation a little. - -''Tis so,' said the Duchess: 'and the moral of that is--"Oh, 'tis love, -'tis love, that makes the world go round!"' - -'Somebody said,' Alice whispered, 'that it's done by everybody minding -their own business!' - -'Ah, well! It means much the same thing,' said the Duchess, digging her -sharp little chin into Alice's shoulder as she added, 'and the moral -of THAT is--"Take care of the sense, and the sounds will take care of -themselves."' - -'How fond she is of finding morals in things!' Alice thought to herself. - -'I dare say you're wondering why I don't put my arm round your waist,' -the Duchess said after a pause: 'the reason is, that I'm doubtful about -the temper of your flamingo. Shall I try the experiment?' - -'HE might bite,' Alice cautiously replied, not feeling at all anxious to -have the experiment tried. - -'Very true,' said the Duchess: 'flamingoes and mustard both bite. And -the moral of that is--"Birds of a feather flock together."' - -'Only mustard isn't a bird,' Alice remarked. - -'Right, as usual,' said the Duchess: 'what a clear way you have of -putting things!' - -'It's a mineral, I THINK,' said Alice. - -'Of course it is,' said the Duchess, who seemed ready to agree to -everything that Alice said; 'there's a large mustard-mine near here. And -the moral of that is--"The more there is of mine, the less there is of -yours."' - -'Oh, I know!' exclaimed Alice, who had not attended to this last remark, -'it's a vegetable. It doesn't look like one, but it is.' - -'I quite agree with you,' said the Duchess; 'and the moral of that -is--"Be what you would seem to be"--or if you'd like it put more -simply--"Never imagine yourself not to be otherwise than what it might -appear to others that what you were or might have been was not otherwise -than what you had been would have appeared to them to be otherwise."' - -'I think I should understand that better,' Alice said very politely, 'if -I had it written down: but I can't quite follow it as you say it.' - -'That's nothing to what I could say if I chose,' the Duchess replied, in -a pleased tone. - -'Pray don't trouble yourself to say it any longer than that,' said -Alice. - -'Oh, don't talk about trouble!' said the Duchess. 'I make you a present -of everything I've said as yet.' - -'A cheap sort of present!' thought Alice. 'I'm glad they don't give -birthday presents like that!' But she did not venture to say it out -loud. - -'Thinking again?' the Duchess asked, with another dig of her sharp -little chin. - -'I've a right to think,' said Alice sharply, for she was beginning to -feel a little worried. - -'Just about as much right,' said the Duchess, 'as pigs have to fly; and -the m--' - -But here, to Alice's great surprise, the Duchess's voice died away, even -in the middle of her favourite word 'moral,' and the arm that was linked -into hers began to tremble. Alice looked up, and there stood the Queen -in front of them, with her arms folded, frowning like a thunderstorm. - -'A fine day, your Majesty!' the Duchess began in a low, weak voice. - -'Now, I give you fair warning,' shouted the Queen, stamping on the -ground as she spoke; 'either you or your head must be off, and that in -about half no time! Take your choice!' - -The Duchess took her choice, and was gone in a moment. - -'Let's go on with the game,' the Queen said to Alice; and Alice was -too much frightened to say a word, but slowly followed her back to the -croquet-ground. - -The other guests had taken advantage of the Queen's absence, and were -resting in the shade: however, the moment they saw her, they hurried -back to the game, the Queen merely remarking that a moment's delay would -cost them their lives. - -All the time they were playing the Queen never left off quarrelling with -the other players, and shouting 'Off with his head!' or 'Off with her -head!' Those whom she sentenced were taken into custody by the soldiers, -who of course had to leave off being arches to do this, so that by -the end of half an hour or so there were no arches left, and all the -players, except the King, the Queen, and Alice, were in custody and -under sentence of execution. - -Then the Queen left off, quite out of breath, and said to Alice, 'Have -you seen the Mock Turtle yet?' - -'No,' said Alice. 'I don't even know what a Mock Turtle is.' - -'It's the thing Mock Turtle Soup is made from,' said the Queen. - -'I never saw one, or heard of one,' said Alice. - -'Come on, then,' said the Queen, 'and he shall tell you his history,' - -As they walked off together, Alice heard the King say in a low voice, -to the company generally, 'You are all pardoned.' 'Come, THAT'S a good -thing!' she said to herself, for she had felt quite unhappy at the -number of executions the Queen had ordered. - -They very soon came upon a Gryphon, lying fast asleep in the sun. -(IF you don't know what a Gryphon is, look at the picture.) 'Up, lazy -thing!' said the Queen, 'and take this young lady to see the Mock -Turtle, and to hear his history. I must go back and see after some -executions I have ordered'; and she walked off, leaving Alice alone with -the Gryphon. Alice did not quite like the look of the creature, but on -the whole she thought it would be quite as safe to stay with it as to go -after that savage Queen: so she waited. - -The Gryphon sat up and rubbed its eyes: then it watched the Queen till -she was out of sight: then it chuckled. 'What fun!' said the Gryphon, -half to itself, half to Alice. - -'What IS the fun?' said Alice. - -'Why, SHE,' said the Gryphon. 'It's all her fancy, that: they never -executes nobody, you know. Come on!' - -'Everybody says "come on!" here,' thought Alice, as she went slowly -after it: 'I never was so ordered about in all my life, never!' - -They had not gone far before they saw the Mock Turtle in the distance, -sitting sad and lonely on a little ledge of rock, and, as they came -nearer, Alice could hear him sighing as if his heart would break. She -pitied him deeply. 'What is his sorrow?' she asked the Gryphon, and the -Gryphon answered, very nearly in the same words as before, 'It's all his -fancy, that: he hasn't got no sorrow, you know. Come on!' - -So they went up to the Mock Turtle, who looked at them with large eyes -full of tears, but said nothing. - -'This here young lady,' said the Gryphon, 'she wants for to know your -history, she do.' - -'I'll tell it her,' said the Mock Turtle in a deep, hollow tone: 'sit -down, both of you, and don't speak a word till I've finished.' - -So they sat down, and nobody spoke for some minutes. Alice thought to -herself, 'I don't see how he can EVEN finish, if he doesn't begin.' But -she waited patiently. - -'Once,' said the Mock Turtle at last, with a deep sigh, 'I was a real -Turtle.' - -These words were followed by a very long silence, broken only by an -occasional exclamation of 'Hjckrrh!' from the Gryphon, and the constant -heavy sobbing of the Mock Turtle. Alice was very nearly getting up and -saying, 'Thank you, sir, for your interesting story,' but she could -not help thinking there MUST be more to come, so she sat still and said -nothing. - -'When we were little,' the Mock Turtle went on at last, more calmly, -though still sobbing a little now and then, 'we went to school in the -sea. The master was an old Turtle--we used to call him Tortoise--' - -'Why did you call him Tortoise, if he wasn't one?' Alice asked. - -'We called him Tortoise because he taught us,' said the Mock Turtle -angrily: 'really you are very dull!' - -'You ought to be ashamed of yourself for asking such a simple question,' -added the Gryphon; and then they both sat silent and looked at poor -Alice, who felt ready to sink into the earth. At last the Gryphon said -to the Mock Turtle, 'Drive on, old fellow! Don't be all day about it!' -and he went on in these words: - -'Yes, we went to school in the sea, though you mayn't believe it--' - -'I never said I didn't!' interrupted Alice. - -'You did,' said the Mock Turtle. - -'Hold your tongue!' added the Gryphon, before Alice could speak again. -The Mock Turtle went on. - -'We had the best of educations--in fact, we went to school every day--' - -'I'VE been to a day-school, too,' said Alice; 'you needn't be so proud -as all that.' - -'With extras?' asked the Mock Turtle a little anxiously. - -'Yes,' said Alice, 'we learned French and music.' - -'And washing?' said the Mock Turtle. - -'Certainly not!' said Alice indignantly. - -'Ah! then yours wasn't a really good school,' said the Mock Turtle in -a tone of great relief. 'Now at OURS they had at the end of the bill, -"French, music, AND WASHING--extra."' - -'You couldn't have wanted it much,' said Alice; 'living at the bottom of -the sea.' - -'I couldn't afford to learn it.' said the Mock Turtle with a sigh. 'I -only took the regular course.' - -'What was that?' inquired Alice. - -'Reeling and Writhing, of course, to begin with,' the Mock Turtle -replied; 'and then the different branches of Arithmetic--Ambition, -Distraction, Uglification, and Derision.' - -'I never heard of "Uglification,"' Alice ventured to say. 'What is it?' - -The Gryphon lifted up both its paws in surprise. 'What! Never heard of -uglifying!' it exclaimed. 'You know what to beautify is, I suppose?' - -'Yes,' said Alice doubtfully: 'it means--to--make--anything--prettier.' - -'Well, then,' the Gryphon went on, 'if you don't know what to uglify is, -you ARE a simpleton.' - -Alice did not feel encouraged to ask any more questions about it, so she -turned to the Mock Turtle, and said 'What else had you to learn?' - -'Well, there was Mystery,' the Mock Turtle replied, counting off -the subjects on his flappers, '--Mystery, ancient and modern, with -Seaography: then Drawling--the Drawling-master was an old conger-eel, -that used to come once a week: HE taught us Drawling, Stretching, and -Fainting in Coils.' - -'What was THAT like?' said Alice. - -'Well, I can't show it you myself,' the Mock Turtle said: 'I'm too -stiff. And the Gryphon never learnt it.' - -'Hadn't time,' said the Gryphon: 'I went to the Classics master, though. -He was an old crab, HE was.' - -'I never went to him,' the Mock Turtle said with a sigh: 'he taught -Laughing and Grief, they used to say.' - -'So he did, so he did,' said the Gryphon, sighing in his turn; and both -creatures hid their faces in their paws. - -'And how many hours a day did you do lessons?' said Alice, in a hurry to -change the subject. - -'Ten hours the first day,' said the Mock Turtle: 'nine the next, and so -on.' - -'What a curious plan!' exclaimed Alice. - -'That's the reason they're called lessons,' the Gryphon remarked: -'because they lessen from day to day.' - -This was quite a new idea to Alice, and she thought it over a little -before she made her next remark. 'Then the eleventh day must have been a -holiday?' - -'Of course it was,' said the Mock Turtle. - -'And how did you manage on the twelfth?' Alice went on eagerly. - -'That's enough about lessons,' the Gryphon interrupted in a very decided -tone: 'tell her something about the games now.' - - - - -CHAPTER 10. The Lobster Quadrille - -The Mock Turtle sighed deeply, and drew the back of one flapper across -his eyes. He looked at Alice, and tried to speak, but for a minute or -two sobs choked his voice. 'Same as if he had a bone in his throat,' -said the Gryphon: and it set to work shaking him and punching him in -the back. At last the Mock Turtle recovered his voice, and, with tears -running down his cheeks, he went on again:-- - -'You may not have lived much under the sea--' ('I haven't,' said -Alice)--'and perhaps you were never even introduced to a lobster--' -(Alice began to say 'I once tasted--' but checked herself hastily, and -said 'No, never') '--so you can have no idea what a delightful thing a -Lobster Quadrille is!' - -'No, indeed,' said Alice. 'What sort of a dance is it?' - -'Why,' said the Gryphon, 'you first form into a line along the -sea-shore--' - -'Two lines!' cried the Mock Turtle. 'Seals, turtles, salmon, and so on; -then, when you've cleared all the jelly-fish out of the way--' - -'THAT generally takes some time,' interrupted the Gryphon. - -'--you advance twice--' - -'Each with a lobster as a partner!' cried the Gryphon. - -'Of course,' the Mock Turtle said: 'advance twice, set to partners--' - -'--change lobsters, and retire in same order,' continued the Gryphon. - -'Then, you know,' the Mock Turtle went on, 'you throw the--' - -'The lobsters!' shouted the Gryphon, with a bound into the air. - -'--as far out to sea as you can--' - -'Swim after them!' screamed the Gryphon. - -'Turn a somersault in the sea!' cried the Mock Turtle, capering wildly -about. - -'Change lobsters again!' yelled the Gryphon at the top of its voice. - -'Back to land again, and that's all the first figure,' said the Mock -Turtle, suddenly dropping his voice; and the two creatures, who had been -jumping about like mad things all this time, sat down again very sadly -and quietly, and looked at Alice. - -'It must be a very pretty dance,' said Alice timidly. - -'Would you like to see a little of it?' said the Mock Turtle. - -'Very much indeed,' said Alice. - -'Come, let's try the first figure!' said the Mock Turtle to the Gryphon. -'We can do without lobsters, you know. Which shall sing?' - -'Oh, YOU sing,' said the Gryphon. 'I've forgotten the words.' - -So they began solemnly dancing round and round Alice, every now and -then treading on her toes when they passed too close, and waving their -forepaws to mark the time, while the Mock Turtle sang this, very slowly -and sadly:-- - - '"Will you walk a little faster?" said a whiting to a snail. - "There's a porpoise close behind us, and he's treading on my tail. - - See how eagerly the lobsters and the turtles all advance! - They are waiting on the shingle--will you come and join the dance? - - Will you, won't you, will you, won't you, will you join the dance? - Will you, won't you, will you, won't you, won't you join the dance? - - "You can really have no notion how delightful it will be - When they take us up and throw us, with the lobsters, out to sea!" - But the snail replied "Too far, too far!" and gave a look askance-- - Said he thanked the whiting kindly, but he would not join the dance. - - Would not, could not, would not, could not, would not join the dance. - Would not, could not, would not, could not, could not join the dance. - - '"What matters it how far we go?" his scaly friend replied. - "There is another shore, you know, upon the other side. - The further off from England the nearer is to France-- - Then turn not pale, beloved snail, but come and join the dance. - - Will you, won't you, will you, won't you, will you join the dance? - Will you, won't you, will you, won't you, won't you join the dance?"' - -'Thank you, it's a very interesting dance to watch,' said Alice, feeling -very glad that it was over at last: 'and I do so like that curious song -about the whiting!' - -'Oh, as to the whiting,' said the Mock Turtle, 'they--you've seen them, -of course?' - -'Yes,' said Alice, 'I've often seen them at dinn--' she checked herself -hastily. - -'I don't know where Dinn may be,' said the Mock Turtle, 'but if you've -seen them so often, of course you know what they're like.' - -'I believe so,' Alice replied thoughtfully. 'They have their tails in -their mouths--and they're all over crumbs.' - -'You're wrong about the crumbs,' said the Mock Turtle: 'crumbs would all -wash off in the sea. But they HAVE their tails in their mouths; and the -reason is--' here the Mock Turtle yawned and shut his eyes.--'Tell her -about the reason and all that,' he said to the Gryphon. - -'The reason is,' said the Gryphon, 'that they WOULD go with the lobsters -to the dance. So they got thrown out to sea. So they had to fall a long -way. So they got their tails fast in their mouths. So they couldn't get -them out again. That's all.' - -'Thank you,' said Alice, 'it's very interesting. I never knew so much -about a whiting before.' - -'I can tell you more than that, if you like,' said the Gryphon. 'Do you -know why it's called a whiting?' - -'I never thought about it,' said Alice. 'Why?' - -'IT DOES THE BOOTS AND SHOES.' the Gryphon replied very solemnly. - -Alice was thoroughly puzzled. 'Does the boots and shoes!' she repeated -in a wondering tone. - -'Why, what are YOUR shoes done with?' said the Gryphon. 'I mean, what -makes them so shiny?' - -Alice looked down at them, and considered a little before she gave her -answer. 'They're done with blacking, I believe.' - -'Boots and shoes under the sea,' the Gryphon went on in a deep voice, -'are done with a whiting. Now you know.' - -'And what are they made of?' Alice asked in a tone of great curiosity. - -'Soles and eels, of course,' the Gryphon replied rather impatiently: -'any shrimp could have told you that.' - -'If I'd been the whiting,' said Alice, whose thoughts were still running -on the song, 'I'd have said to the porpoise, "Keep back, please: we -don't want YOU with us!"' - -'They were obliged to have him with them,' the Mock Turtle said: 'no -wise fish would go anywhere without a porpoise.' - -'Wouldn't it really?' said Alice in a tone of great surprise. - -'Of course not,' said the Mock Turtle: 'why, if a fish came to ME, and -told me he was going a journey, I should say "With what porpoise?"' - -'Don't you mean "purpose"?' said Alice. - -'I mean what I say,' the Mock Turtle replied in an offended tone. And -the Gryphon added 'Come, let's hear some of YOUR adventures.' - -'I could tell you my adventures--beginning from this morning,' said -Alice a little timidly: 'but it's no use going back to yesterday, -because I was a different person then.' - -'Explain all that,' said the Mock Turtle. - -'No, no! The adventures first,' said the Gryphon in an impatient tone: -'explanations take such a dreadful time.' - -So Alice began telling them her adventures from the time when she first -saw the White Rabbit. She was a little nervous about it just at first, -the two creatures got so close to her, one on each side, and opened -their eyes and mouths so VERY wide, but she gained courage as she went -on. Her listeners were perfectly quiet till she got to the part about -her repeating 'YOU ARE OLD, FATHER WILLIAM,' to the Caterpillar, and the -words all coming different, and then the Mock Turtle drew a long breath, -and said 'That's very curious.' - -'It's all about as curious as it can be,' said the Gryphon. - -'It all came different!' the Mock Turtle repeated thoughtfully. 'I -should like to hear her try and repeat something now. Tell her to -begin.' He looked at the Gryphon as if he thought it had some kind of -authority over Alice. - -'Stand up and repeat "'TIS THE VOICE OF THE SLUGGARD,"' said the -Gryphon. - -'How the creatures order one about, and make one repeat lessons!' -thought Alice; 'I might as well be at school at once.' However, she -got up, and began to repeat it, but her head was so full of the Lobster -Quadrille, that she hardly knew what she was saying, and the words came -very queer indeed:-- - - ''Tis the voice of the Lobster; I heard him declare, - "You have baked me too brown, I must sugar my hair." - As a duck with its eyelids, so he with his nose - Trims his belt and his buttons, and turns out his toes.' - - [later editions continued as follows - When the sands are all dry, he is gay as a lark, - And will talk in contemptuous tones of the Shark, - But, when the tide rises and sharks are around, - His voice has a timid and tremulous sound.] - -'That's different from what I used to say when I was a child,' said the -Gryphon. - -'Well, I never heard it before,' said the Mock Turtle; 'but it sounds -uncommon nonsense.' - -Alice said nothing; she had sat down with her face in her hands, -wondering if anything would EVER happen in a natural way again. - -'I should like to have it explained,' said the Mock Turtle. - -'She can't explain it,' said the Gryphon hastily. 'Go on with the next -verse.' - -'But about his toes?' the Mock Turtle persisted. 'How COULD he turn them -out with his nose, you know?' - -'It's the first position in dancing.' Alice said; but was dreadfully -puzzled by the whole thing, and longed to change the subject. - -'Go on with the next verse,' the Gryphon repeated impatiently: 'it -begins "I passed by his garden."' - -Alice did not dare to disobey, though she felt sure it would all come -wrong, and she went on in a trembling voice:-- - - 'I passed by his garden, and marked, with one eye, - How the Owl and the Panther were sharing a pie--' - - [later editions continued as follows - The Panther took pie-crust, and gravy, and meat, - While the Owl had the dish as its share of the treat. - When the pie was all finished, the Owl, as a boon, - Was kindly permitted to pocket the spoon: - While the Panther received knife and fork with a growl, - And concluded the banquet--] - -'What IS the use of repeating all that stuff,' the Mock Turtle -interrupted, 'if you don't explain it as you go on? It's by far the most -confusing thing I ever heard!' - -'Yes, I think you'd better leave off,' said the Gryphon: and Alice was -only too glad to do so. - -'Shall we try another figure of the Lobster Quadrille?' the Gryphon went -on. 'Or would you like the Mock Turtle to sing you a song?' - -'Oh, a song, please, if the Mock Turtle would be so kind,' Alice -replied, so eagerly that the Gryphon said, in a rather offended tone, -'Hm! No accounting for tastes! Sing her "Turtle Soup," will you, old -fellow?' - -The Mock Turtle sighed deeply, and began, in a voice sometimes choked -with sobs, to sing this:-- - - 'Beautiful Soup, so rich and green, - Waiting in a hot tureen! - Who for such dainties would not stoop? - Soup of the evening, beautiful Soup! - Soup of the evening, beautiful Soup! - Beau--ootiful Soo--oop! - Beau--ootiful Soo--oop! - Soo--oop of the e--e--evening, - Beautiful, beautiful Soup! - - 'Beautiful Soup! Who cares for fish, - Game, or any other dish? - Who would not give all else for two - Pennyworth only of beautiful Soup? - Pennyworth only of beautiful Soup? - Beau--ootiful Soo--oop! - Beau--ootiful Soo--oop! - Soo--oop of the e--e--evening, - Beautiful, beauti--FUL SOUP!' - -'Chorus again!' cried the Gryphon, and the Mock Turtle had just begun -to repeat it, when a cry of 'The trial's beginning!' was heard in the -distance. - -'Come on!' cried the Gryphon, and, taking Alice by the hand, it hurried -off, without waiting for the end of the song. - -'What trial is it?' Alice panted as she ran; but the Gryphon only -answered 'Come on!' and ran the faster, while more and more faintly -came, carried on the breeze that followed them, the melancholy words:-- - - 'Soo--oop of the e--e--evening, - Beautiful, beautiful Soup!' - - - - -CHAPTER 11. Who Stole the Tarts? - -The King and Queen of Hearts were seated on their throne when they -arrived, with a great crowd assembled about them--all sorts of little -birds and beasts, as well as the whole pack of cards: the Knave was -standing before them, in chains, with a soldier on each side to guard -him; and near the King was the White Rabbit, with a trumpet in one hand, -and a scroll of parchment in the other. In the very middle of the court -was a table, with a large dish of tarts upon it: they looked so good, -that it made Alice quite hungry to look at them--'I wish they'd get the -trial done,' she thought, 'and hand round the refreshments!' But there -seemed to be no chance of this, so she began looking at everything about -her, to pass away the time. - -Alice had never been in a court of justice before, but she had read -about them in books, and she was quite pleased to find that she knew -the name of nearly everything there. 'That's the judge,' she said to -herself, 'because of his great wig.' - -The judge, by the way, was the King; and as he wore his crown over the -wig, (look at the frontispiece if you want to see how he did it,) he did -not look at all comfortable, and it was certainly not becoming. - -'And that's the jury-box,' thought Alice, 'and those twelve creatures,' -(she was obliged to say 'creatures,' you see, because some of them were -animals, and some were birds,) 'I suppose they are the jurors.' She said -this last word two or three times over to herself, being rather proud of -it: for she thought, and rightly too, that very few little girls of her -age knew the meaning of it at all. However, 'jury-men' would have done -just as well. - -The twelve jurors were all writing very busily on slates. 'What are they -doing?' Alice whispered to the Gryphon. 'They can't have anything to put -down yet, before the trial's begun.' - -'They're putting down their names,' the Gryphon whispered in reply, 'for -fear they should forget them before the end of the trial.' - -'Stupid things!' Alice began in a loud, indignant voice, but she stopped -hastily, for the White Rabbit cried out, 'Silence in the court!' and the -King put on his spectacles and looked anxiously round, to make out who -was talking. - -Alice could see, as well as if she were looking over their shoulders, -that all the jurors were writing down 'stupid things!' on their slates, -and she could even make out that one of them didn't know how to spell -'stupid,' and that he had to ask his neighbour to tell him. 'A nice -muddle their slates'll be in before the trial's over!' thought Alice. - -One of the jurors had a pencil that squeaked. This of course, Alice -could not stand, and she went round the court and got behind him, and -very soon found an opportunity of taking it away. She did it so quickly -that the poor little juror (it was Bill, the Lizard) could not make out -at all what had become of it; so, after hunting all about for it, he was -obliged to write with one finger for the rest of the day; and this was -of very little use, as it left no mark on the slate. - -'Herald, read the accusation!' said the King. - -On this the White Rabbit blew three blasts on the trumpet, and then -unrolled the parchment scroll, and read as follows:-- - - 'The Queen of Hearts, she made some tarts, - All on a summer day: - The Knave of Hearts, he stole those tarts, - And took them quite away!' - -'Consider your verdict,' the King said to the jury. - -'Not yet, not yet!' the Rabbit hastily interrupted. 'There's a great -deal to come before that!' - -'Call the first witness,' said the King; and the White Rabbit blew three -blasts on the trumpet, and called out, 'First witness!' - -The first witness was the Hatter. He came in with a teacup in one -hand and a piece of bread-and-butter in the other. 'I beg pardon, your -Majesty,' he began, 'for bringing these in: but I hadn't quite finished -my tea when I was sent for.' - -'You ought to have finished,' said the King. 'When did you begin?' - -The Hatter looked at the March Hare, who had followed him into the -court, arm-in-arm with the Dormouse. 'Fourteenth of March, I think it -was,' he said. - -'Fifteenth,' said the March Hare. - -'Sixteenth,' added the Dormouse. - -'Write that down,' the King said to the jury, and the jury eagerly -wrote down all three dates on their slates, and then added them up, and -reduced the answer to shillings and pence. - -'Take off your hat,' the King said to the Hatter. - -'It isn't mine,' said the Hatter. - -'Stolen!' the King exclaimed, turning to the jury, who instantly made a -memorandum of the fact. - -'I keep them to sell,' the Hatter added as an explanation; 'I've none of -my own. I'm a hatter.' - -Here the Queen put on her spectacles, and began staring at the Hatter, -who turned pale and fidgeted. - -'Give your evidence,' said the King; 'and don't be nervous, or I'll have -you executed on the spot.' - -This did not seem to encourage the witness at all: he kept shifting -from one foot to the other, looking uneasily at the Queen, and in -his confusion he bit a large piece out of his teacup instead of the -bread-and-butter. - -Just at this moment Alice felt a very curious sensation, which puzzled -her a good deal until she made out what it was: she was beginning to -grow larger again, and she thought at first she would get up and leave -the court; but on second thoughts she decided to remain where she was as -long as there was room for her. - -'I wish you wouldn't squeeze so.' said the Dormouse, who was sitting -next to her. 'I can hardly breathe.' - -'I can't help it,' said Alice very meekly: 'I'm growing.' - -'You've no right to grow here,' said the Dormouse. - -'Don't talk nonsense,' said Alice more boldly: 'you know you're growing -too.' - -'Yes, but I grow at a reasonable pace,' said the Dormouse: 'not in that -ridiculous fashion.' And he got up very sulkily and crossed over to the -other side of the court. - -All this time the Queen had never left off staring at the Hatter, and, -just as the Dormouse crossed the court, she said to one of the officers -of the court, 'Bring me the list of the singers in the last concert!' on -which the wretched Hatter trembled so, that he shook both his shoes off. - -'Give your evidence,' the King repeated angrily, 'or I'll have you -executed, whether you're nervous or not.' - -'I'm a poor man, your Majesty,' the Hatter began, in a trembling voice, -'--and I hadn't begun my tea--not above a week or so--and what with the -bread-and-butter getting so thin--and the twinkling of the tea--' - -'The twinkling of the what?' said the King. - -'It began with the tea,' the Hatter replied. - -'Of course twinkling begins with a T!' said the King sharply. 'Do you -take me for a dunce? Go on!' - -'I'm a poor man,' the Hatter went on, 'and most things twinkled after -that--only the March Hare said--' - -'I didn't!' the March Hare interrupted in a great hurry. - -'You did!' said the Hatter. - -'I deny it!' said the March Hare. - -'He denies it,' said the King: 'leave out that part.' - -'Well, at any rate, the Dormouse said--' the Hatter went on, looking -anxiously round to see if he would deny it too: but the Dormouse denied -nothing, being fast asleep. - -'After that,' continued the Hatter, 'I cut some more bread-and-butter--' - -'But what did the Dormouse say?' one of the jury asked. - -'That I can't remember,' said the Hatter. - -'You MUST remember,' remarked the King, 'or I'll have you executed.' - -The miserable Hatter dropped his teacup and bread-and-butter, and went -down on one knee. 'I'm a poor man, your Majesty,' he began. - -'You're a very poor speaker,' said the King. - -Here one of the guinea-pigs cheered, and was immediately suppressed by -the officers of the court. (As that is rather a hard word, I will just -explain to you how it was done. They had a large canvas bag, which tied -up at the mouth with strings: into this they slipped the guinea-pig, -head first, and then sat upon it.) - -'I'm glad I've seen that done,' thought Alice. 'I've so often read -in the newspapers, at the end of trials, "There was some attempts -at applause, which was immediately suppressed by the officers of the -court," and I never understood what it meant till now.' - -'If that's all you know about it, you may stand down,' continued the -King. - -'I can't go no lower,' said the Hatter: 'I'm on the floor, as it is.' - -'Then you may SIT down,' the King replied. - -Here the other guinea-pig cheered, and was suppressed. - -'Come, that finished the guinea-pigs!' thought Alice. 'Now we shall get -on better.' - -'I'd rather finish my tea,' said the Hatter, with an anxious look at the -Queen, who was reading the list of singers. - -'You may go,' said the King, and the Hatter hurriedly left the court, -without even waiting to put his shoes on. - -'--and just take his head off outside,' the Queen added to one of the -officers: but the Hatter was out of sight before the officer could get -to the door. - -'Call the next witness!' said the King. - -The next witness was the Duchess's cook. She carried the pepper-box in -her hand, and Alice guessed who it was, even before she got into the -court, by the way the people near the door began sneezing all at once. - -'Give your evidence,' said the King. - -'Shan't,' said the cook. - -The King looked anxiously at the White Rabbit, who said in a low voice, -'Your Majesty must cross-examine THIS witness.' - -'Well, if I must, I must,' the King said, with a melancholy air, and, -after folding his arms and frowning at the cook till his eyes were -nearly out of sight, he said in a deep voice, 'What are tarts made of?' - -'Pepper, mostly,' said the cook. - -'Treacle,' said a sleepy voice behind her. - -'Collar that Dormouse,' the Queen shrieked out. 'Behead that Dormouse! -Turn that Dormouse out of court! Suppress him! Pinch him! Off with his -whiskers!' - -For some minutes the whole court was in confusion, getting the Dormouse -turned out, and, by the time they had settled down again, the cook had -disappeared. - -'Never mind!' said the King, with an air of great relief. 'Call the next -witness.' And he added in an undertone to the Queen, 'Really, my dear, -YOU must cross-examine the next witness. It quite makes my forehead -ache!' - -Alice watched the White Rabbit as he fumbled over the list, feeling very -curious to see what the next witness would be like, '--for they haven't -got much evidence YET,' she said to herself. Imagine her surprise, when -the White Rabbit read out, at the top of his shrill little voice, the -name 'Alice!' - - - - CHAPTER 12 - - Alice's Evidence - - -'Here!' cried Alice, quite forgetting in the flurry of the moment how -large she had grown in the last few minutes, and she jumped up in such -a hurry that she tipped over the jury-box with the edge of her skirt, -upsetting all the jurymen on to the heads of the crowd below, and there -they lay sprawling about, reminding her very much of a globe of goldfish -she had accidentally upset the week before. - -'Oh, I BEG your pardon!' she exclaimed in a tone of great dismay, and -began picking them up again as quickly as she could, for the accident of -the goldfish kept running in her head, and she had a vague sort of idea -that they must be collected at once and put back into the jury-box, or -they would die. - -'The trial cannot proceed,' said the King in a very grave voice, 'until -all the jurymen are back in their proper places--ALL,' he repeated with -great emphasis, looking hard at Alice as he said do. - -Alice looked at the jury-box, and saw that, in her haste, she had put -the Lizard in head downwards, and the poor little thing was waving its -tail about in a melancholy way, being quite unable to move. She soon got -it out again, and put it right; 'not that it signifies much,' she said -to herself; 'I should think it would be QUITE as much use in the trial -one way up as the other.' - -As soon as the jury had a little recovered from the shock of being -upset, and their slates and pencils had been found and handed back to -them, they set to work very diligently to write out a history of the -accident, all except the Lizard, who seemed too much overcome to do -anything but sit with its mouth open, gazing up into the roof of the -court. - -'What do you know about this business?' the King said to Alice. - -'Nothing,' said Alice. - -'Nothing WHATEVER?' persisted the King. - -'Nothing whatever,' said Alice. - -'That's very important,' the King said, turning to the jury. They were -just beginning to write this down on their slates, when the White Rabbit -interrupted: 'UNimportant, your Majesty means, of course,' he said in a -very respectful tone, but frowning and making faces at him as he spoke. - -'UNimportant, of course, I meant,' the King hastily said, and went on -to himself in an undertone, - -'important--unimportant--unimportant--important--' as if he were trying -which word sounded best. - -Some of the jury wrote it down 'important,' and some 'unimportant.' -Alice could see this, as she was near enough to look over their slates; -'but it doesn't matter a bit,' she thought to herself. - -At this moment the King, who had been for some time busily writing in -his note-book, cackled out 'Silence!' and read out from his book, 'Rule -Forty-two. ALL PERSONS MORE THAN A MILE HIGH TO LEAVE THE COURT.' - -Everybody looked at Alice. - -'I'M not a mile high,' said Alice. - -'You are,' said the King. - -'Nearly two miles high,' added the Queen. - -'Well, I shan't go, at any rate,' said Alice: 'besides, that's not a -regular rule: you invented it just now.' - -'It's the oldest rule in the book,' said the King. - -'Then it ought to be Number One,' said Alice. - -The King turned pale, and shut his note-book hastily. 'Consider your -verdict,' he said to the jury, in a low, trembling voice. - -'There's more evidence to come yet, please your Majesty,' said the White -Rabbit, jumping up in a great hurry; 'this paper has just been picked -up.' - -'What's in it?' said the Queen. - -'I haven't opened it yet,' said the White Rabbit, 'but it seems to be a -letter, written by the prisoner to--to somebody.' - -'It must have been that,' said the King, 'unless it was written to -nobody, which isn't usual, you know.' - -'Who is it directed to?' said one of the jurymen. - -'It isn't directed at all,' said the White Rabbit; 'in fact, there's -nothing written on the OUTSIDE.' He unfolded the paper as he spoke, and -added 'It isn't a letter, after all: it's a set of verses.' - -'Are they in the prisoner's handwriting?' asked another of the jurymen. - -'No, they're not,' said the White Rabbit, 'and that's the queerest thing -about it.' (The jury all looked puzzled.) - -'He must have imitated somebody else's hand,' said the King. (The jury -all brightened up again.) - -'Please your Majesty,' said the Knave, 'I didn't write it, and they -can't prove I did: there's no name signed at the end.' - -'If you didn't sign it,' said the King, 'that only makes the matter -worse. You MUST have meant some mischief, or else you'd have signed your -name like an honest man.' - -There was a general clapping of hands at this: it was the first really -clever thing the King had said that day. - -'That PROVES his guilt,' said the Queen. - -'It proves nothing of the sort!' said Alice. 'Why, you don't even know -what they're about!' - -'Read them,' said the King. - -The White Rabbit put on his spectacles. 'Where shall I begin, please -your Majesty?' he asked. - -'Begin at the beginning,' the King said gravely, 'and go on till you -come to the end: then stop.' - -These were the verses the White Rabbit read:-- - - 'They told me you had been to her, - And mentioned me to him: - She gave me a good character, - But said I could not swim. - - He sent them word I had not gone - (We know it to be true): - If she should push the matter on, - What would become of you? - - I gave her one, they gave him two, - You gave us three or more; - They all returned from him to you, - Though they were mine before. - - If I or she should chance to be - Involved in this affair, - He trusts to you to set them free, - Exactly as we were. - - My notion was that you had been - (Before she had this fit) - An obstacle that came between - Him, and ourselves, and it. - - Don't let him know she liked them best, - For this must ever be - A secret, kept from all the rest, - Between yourself and me.' - -'That's the most important piece of evidence we've heard yet,' said the -King, rubbing his hands; 'so now let the jury--' - -'If any one of them can explain it,' said Alice, (she had grown so large -in the last few minutes that she wasn't a bit afraid of interrupting -him,) 'I'll give him sixpence. _I_ don't believe there's an atom of -meaning in it.' - -The jury all wrote down on their slates, 'SHE doesn't believe there's an -atom of meaning in it,' but none of them attempted to explain the paper. - -'If there's no meaning in it,' said the King, 'that saves a world of -trouble, you know, as we needn't try to find any. And yet I don't know,' -he went on, spreading out the verses on his knee, and looking at them -with one eye; 'I seem to see some meaning in them, after all. "--SAID -I COULD NOT SWIM--" you can't swim, can you?' he added, turning to the -Knave. - -The Knave shook his head sadly. 'Do I look like it?' he said. (Which he -certainly did NOT, being made entirely of cardboard.) - -'All right, so far,' said the King, and he went on muttering over -the verses to himself: '"WE KNOW IT TO BE TRUE--" that's the jury, of -course--"I GAVE HER ONE, THEY GAVE HIM TWO--" why, that must be what he -did with the tarts, you know--' - -'But, it goes on "THEY ALL RETURNED FROM HIM TO YOU,"' said Alice. - -'Why, there they are!' said the King triumphantly, pointing to the tarts -on the table. 'Nothing can be clearer than THAT. Then again--"BEFORE SHE -HAD THIS FIT--" you never had fits, my dear, I think?' he said to the -Queen. - -'Never!' said the Queen furiously, throwing an inkstand at the Lizard -as she spoke. (The unfortunate little Bill had left off writing on his -slate with one finger, as he found it made no mark; but he now hastily -began again, using the ink, that was trickling down his face, as long as -it lasted.) - -'Then the words don't FIT you,' said the King, looking round the court -with a smile. There was a dead silence. - -'It's a pun!' the King added in an offended tone, and everybody laughed, -'Let the jury consider their verdict,' the King said, for about the -twentieth time that day. - -'No, no!' said the Queen. 'Sentence first--verdict afterwards.' - -'Stuff and nonsense!' said Alice loudly. 'The idea of having the -sentence first!' - -'Hold your tongue!' said the Queen, turning purple. - -'I won't!' said Alice. - -'Off with her head!' the Queen shouted at the top of her voice. Nobody -moved. - -'Who cares for you?' said Alice, (she had grown to her full size by this -time.) 'You're nothing but a pack of cards!' - -At this the whole pack rose up into the air, and came flying down upon -her: she gave a little scream, half of fright and half of anger, and -tried to beat them off, and found herself lying on the bank, with her -head in the lap of her sister, who was gently brushing away some dead -leaves that had fluttered down from the trees upon her face. - -'Wake up, Alice dear!' said her sister; 'Why, what a long sleep you've -had!' - -'Oh, I've had such a curious dream!' said Alice, and she told her -sister, as well as she could remember them, all these strange Adventures -of hers that you have just been reading about; and when she had -finished, her sister kissed her, and said, 'It WAS a curious dream, -dear, certainly: but now run in to your tea; it's getting late.' So -Alice got up and ran off, thinking while she ran, as well she might, -what a wonderful dream it had been. - -But her sister sat still just as she left her, leaning her head on her -hand, watching the setting sun, and thinking of little Alice and all her -wonderful Adventures, till she too began dreaming after a fashion, and -this was her dream:-- - -First, she dreamed of little Alice herself, and once again the tiny -hands were clasped upon her knee, and the bright eager eyes were looking -up into hers--she could hear the very tones of her voice, and see that -queer little toss of her head to keep back the wandering hair that -WOULD always get into her eyes--and still as she listened, or seemed to -listen, the whole place around her became alive the strange creatures of -her little sister's dream. - -The long grass rustled at her feet as the White Rabbit hurried by--the -frightened Mouse splashed his way through the neighbouring pool--she -could hear the rattle of the teacups as the March Hare and his friends -shared their never-ending meal, and the shrill voice of the Queen -ordering off her unfortunate guests to execution--once more the pig-baby -was sneezing on the Duchess's knee, while plates and dishes crashed -around it--once more the shriek of the Gryphon, the squeaking of the -Lizard's slate-pencil, and the choking of the suppressed guinea-pigs, -filled the air, mixed up with the distant sobs of the miserable Mock -Turtle. - -So she sat on, with closed eyes, and half believed herself in -Wonderland, though she knew she had but to open them again, and all -would change to dull reality--the grass would be only rustling in the -wind, and the pool rippling to the waving of the reeds--the rattling -teacups would change to tinkling sheep-bells, and the Queen's shrill -cries to the voice of the shepherd boy--and the sneeze of the baby, the -shriek of the Gryphon, and all the other queer noises, would change (she -knew) to the confused clamour of the busy farm-yard--while the lowing -of the cattle in the distance would take the place of the Mock Turtle's -heavy sobs. - -Lastly, she pictured to herself how this same little sister of hers -would, in the after-time, be herself a grown woman; and how she would -keep, through all her riper years, the simple and loving heart of her -childhood: and how she would gather about her other little children, and -make THEIR eyes bright and eager with many a strange tale, perhaps even -with the dream of Wonderland of long ago: and how she would feel with -all their simple sorrows, and find a pleasure in all their simple joys, -remembering her own child-life, and the happy summer days. - - THE END - - - - - -End of Project Gutenberg's Alice's Adventures in Wonderland, by Lewis Carroll - -*** END OF THIS PROJECT GUTENBERG EBOOK ALICE'S ADVENTURES IN WONDERLAND *** - -***** This file should be named 11.txt or 11.zip ***** -This and all associated files of various formats will be found in: - http://www.gutenberg.org/1/11/ - - - -Updated editions will replace the previous one--the old editions -will be renamed. - -Creating the works from public domain print editions means that no -one owns a United States copyright in these works, so the Foundation -(and you!) can copy and distribute it in the United States without -permission and without paying copyright royalties. Special rules, -set forth in the General Terms of Use part of this license, apply to -copying and distributing Project Gutenberg-tm electronic works to -protect the PROJECT GUTENBERG-tm concept and trademark. Project -Gutenberg is a registered trademark, and may not be used if you -charge for the eBooks, unless you receive specific permission. If you -do not charge anything for copies of this eBook, complying with the -rules is very easy. You may use this eBook for nearly any purpose -such as creation of derivative works, reports, performances and -research. They may be modified and printed and given away--you may do -practically ANYTHING with public domain eBooks. Redistribution is -subject to the trademark license, especially commercial -redistribution. - - - -*** START: FULL LICENSE *** - -THE FULL PROJECT GUTENBERG LICENSE -PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK - -To protect the Project Gutenberg-tm mission of promoting the free -distribution of electronic works, by using or distributing this work -(or any other work associated in any way with the phrase "Project -Gutenberg"), you agree to comply with all the terms of the Full Project -Gutenberg-tm License (available with this file or online at -http://gutenberg.org/license). - - -Section 1. General Terms of Use and Redistributing Project Gutenberg-tm -electronic works - -1.A. By reading or using any part of this Project Gutenberg-tm -electronic work, you indicate that you have read, understand, agree to -and accept all the terms of this license and intellectual property -(trademark/copyright) agreement. If you do not agree to abide by all -the terms of this agreement, you must cease using and return or destroy -all copies of Project Gutenberg-tm electronic works in your possession. -If you paid a fee for obtaining a copy of or access to a Project -Gutenberg-tm electronic work and you do not agree to be bound by the -terms of this agreement, you may obtain a refund from the person or -entity to whom you paid the fee as set forth in paragraph 1.E.8. - -1.B. "Project Gutenberg" is a registered trademark. It may only be -used on or associated in any way with an electronic work by people who -agree to be bound by the terms of this agreement. There are a few -things that you can do with most Project Gutenberg-tm electronic works -even without complying with the full terms of this agreement. See -paragraph 1.C below. There are a lot of things you can do with Project -Gutenberg-tm electronic works if you follow the terms of this agreement -and help preserve free future access to Project Gutenberg-tm electronic -works. See paragraph 1.E below. - -1.C. The Project Gutenberg Literary Archive Foundation ("the Foundation" -or PGLAF), owns a compilation copyright in the collection of Project -Gutenberg-tm electronic works. Nearly all the individual works in the -collection are in the public domain in the United States. If an -individual work is in the public domain in the United States and you are -located in the United States, we do not claim a right to prevent you from -copying, distributing, performing, displaying or creating derivative -works based on the work as long as all references to Project Gutenberg -are removed. Of course, we hope that you will support the Project -Gutenberg-tm mission of promoting free access to electronic works by -freely sharing Project Gutenberg-tm works in compliance with the terms of -this agreement for keeping the Project Gutenberg-tm name associated with -the work. You can easily comply with the terms of this agreement by -keeping this work in the same format with its attached full Project -Gutenberg-tm License when you share it without charge with others. - -1.D. The copyright laws of the place where you are located also govern -what you can do with this work. Copyright laws in most countries are in -a constant state of change. If you are outside the United States, check -the laws of your country in addition to the terms of this agreement -before downloading, copying, displaying, performing, distributing or -creating derivative works based on this work or any other Project -Gutenberg-tm work. The Foundation makes no representations concerning -the copyright status of any work in any country outside the United -States. - -1.E. Unless you have removed all references to Project Gutenberg: - -1.E.1. The following sentence, with active links to, or other immediate -access to, the full Project Gutenberg-tm License must appear prominently -whenever any copy of a Project Gutenberg-tm work (any work on which the -phrase "Project Gutenberg" appears, or with which the phrase "Project -Gutenberg" is associated) is accessed, displayed, performed, viewed, -copied or distributed: - -This eBook is for the use of anyone anywhere at no cost and with -almost no restrictions whatsoever. You may copy it, give it away or -re-use it under the terms of the Project Gutenberg License included -with this eBook or online at www.gutenberg.org - -1.E.2. If an individual Project Gutenberg-tm electronic work is derived -from the public domain (does not contain a notice indicating that it is -posted with permission of the copyright holder), the work can be copied -and distributed to anyone in the United States without paying any fees -or charges. If you are redistributing or providing access to a work -with the phrase "Project Gutenberg" associated with or appearing on the -work, you must comply either with the requirements of paragraphs 1.E.1 -through 1.E.7 or obtain permission for the use of the work and the -Project Gutenberg-tm trademark as set forth in paragraphs 1.E.8 or -1.E.9. - -1.E.3. If an individual Project Gutenberg-tm electronic work is posted -with the permission of the copyright holder, your use and distribution -must comply with both paragraphs 1.E.1 through 1.E.7 and any additional -terms imposed by the copyright holder. Additional terms will be linked -to the Project Gutenberg-tm License for all works posted with the -permission of the copyright holder found at the beginning of this work. - -1.E.4. Do not unlink or detach or remove the full Project Gutenberg-tm -License terms from this work, or any files containing a part of this -work or any other work associated with Project Gutenberg-tm. - -1.E.5. Do not copy, display, perform, distribute or redistribute this -electronic work, or any part of this electronic work, without -prominently displaying the sentence set forth in paragraph 1.E.1 with -active links or immediate access to the full terms of the Project -Gutenberg-tm License. - -1.E.6. You may convert to and distribute this work in any binary, -compressed, marked up, nonproprietary or proprietary form, including any -word processing or hypertext form. However, if you provide access to or -distribute copies of a Project Gutenberg-tm work in a format other than -"Plain Vanilla ASCII" or other format used in the official version -posted on the official Project Gutenberg-tm web site (www.gutenberg.org), -you must, at no additional cost, fee or expense to the user, provide a -copy, a means of exporting a copy, or a means of obtaining a copy upon -request, of the work in its original "Plain Vanilla ASCII" or other -form. Any alternate format must include the full Project Gutenberg-tm -License as specified in paragraph 1.E.1. - -1.E.7. Do not charge a fee for access to, viewing, displaying, -performing, copying or distributing any Project Gutenberg-tm works -unless you comply with paragraph 1.E.8 or 1.E.9. - -1.E.8. You may charge a reasonable fee for copies of or providing -access to or distributing Project Gutenberg-tm electronic works provided -that - -- You pay a royalty fee of 20% of the gross profits you derive from - the use of Project Gutenberg-tm works calculated using the method - you already use to calculate your applicable taxes. The fee is - owed to the owner of the Project Gutenberg-tm trademark, but he - has agreed to donate royalties under this paragraph to the - Project Gutenberg Literary Archive Foundation. Royalty payments - must be paid within 60 days following each date on which you - prepare (or are legally required to prepare) your periodic tax - returns. Royalty payments should be clearly marked as such and - sent to the Project Gutenberg Literary Archive Foundation at the - address specified in Section 4, "Information about donations to - the Project Gutenberg Literary Archive Foundation." - -- You provide a full refund of any money paid by a user who notifies - you in writing (or by e-mail) within 30 days of receipt that s/he - does not agree to the terms of the full Project Gutenberg-tm - License. You must require such a user to return or - destroy all copies of the works possessed in a physical medium - and discontinue all use of and all access to other copies of - Project Gutenberg-tm works. - -- You provide, in accordance with paragraph 1.F.3, a full refund of any - money paid for a work or a replacement copy, if a defect in the - electronic work is discovered and reported to you within 90 days - of receipt of the work. - -- You comply with all other terms of this agreement for free - distribution of Project Gutenberg-tm works. - -1.E.9. If you wish to charge a fee or distribute a Project Gutenberg-tm -electronic work or group of works on different terms than are set -forth in this agreement, you must obtain permission in writing from -both the Project Gutenberg Literary Archive Foundation and Michael -Hart, the owner of the Project Gutenberg-tm trademark. Contact the -Foundation as set forth in Section 3 below. - -1.F. - -1.F.1. Project Gutenberg volunteers and employees expend considerable -effort to identify, do copyright research on, transcribe and proofread -public domain works in creating the Project Gutenberg-tm -collection. Despite these efforts, Project Gutenberg-tm electronic -works, and the medium on which they may be stored, may contain -"Defects," such as, but not limited to, incomplete, inaccurate or -corrupt data, transcription errors, a copyright or other intellectual -property infringement, a defective or damaged disk or other medium, a -computer virus, or computer codes that damage or cannot be read by -your equipment. - -1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except for the "Right -of Replacement or Refund" described in paragraph 1.F.3, the Project -Gutenberg Literary Archive Foundation, the owner of the Project -Gutenberg-tm trademark, and any other party distributing a Project -Gutenberg-tm electronic work under this agreement, disclaim all -liability to you for damages, costs and expenses, including legal -fees. YOU AGREE THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE, STRICT -LIABILITY, BREACH OF WARRANTY OR BREACH OF CONTRACT EXCEPT THOSE -PROVIDED IN PARAGRAPH F3. YOU AGREE THAT THE FOUNDATION, THE -TRADEMARK OWNER, AND ANY DISTRIBUTOR UNDER THIS AGREEMENT WILL NOT BE -LIABLE TO YOU FOR ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE OR -INCIDENTAL DAMAGES EVEN IF YOU GIVE NOTICE OF THE POSSIBILITY OF SUCH -DAMAGE. - -1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you discover a -defect in this electronic work within 90 days of receiving it, you can -receive a refund of the money (if any) you paid for it by sending a -written explanation to the person you received the work from. If you -received the work on a physical medium, you must return the medium with -your written explanation. The person or entity that provided you with -the defective work may elect to provide a replacement copy in lieu of a -refund. If you received the work electronically, the person or entity -providing it to you may choose to give you a second opportunity to -receive the work electronically in lieu of a refund. If the second copy -is also defective, you may demand a refund in writing without further -opportunities to fix the problem. - -1.F.4. Except for the limited right of replacement or refund set forth -in paragraph 1.F.3, this work is provided to you 'AS-IS' WITH NO OTHER -WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO -WARRANTIES OF MERCHANTIBILITY OR FITNESS FOR ANY PURPOSE. - -1.F.5. Some states do not allow disclaimers of certain implied -warranties or the exclusion or limitation of certain types of damages. -If any disclaimer or limitation set forth in this agreement violates the -law of the state applicable to this agreement, the agreement shall be -interpreted to make the maximum disclaimer or limitation permitted by -the applicable state law. The invalidity or unenforceability of any -provision of this agreement shall not void the remaining provisions. - -1.F.6. INDEMNITY - You agree to indemnify and hold the Foundation, the -trademark owner, any agent or employee of the Foundation, anyone -providing copies of Project Gutenberg-tm electronic works in accordance -with this agreement, and any volunteers associated with the production, -promotion and distribution of Project Gutenberg-tm electronic works, -harmless from all liability, costs and expenses, including legal fees, -that arise directly or indirectly from any of the following which you do -or cause to occur: (a) distribution of this or any Project Gutenberg-tm -work, (b) alteration, modification, or additions or deletions to any -Project Gutenberg-tm work, and (c) any Defect you cause. - - -Section 2. Information about the Mission of Project Gutenberg-tm - -Project Gutenberg-tm is synonymous with the free distribution of -electronic works in formats readable by the widest variety of computers -including obsolete, old, middle-aged and new computers. It exists -because of the efforts of hundreds of volunteers and donations from -people in all walks of life. - -Volunteers and financial support to provide volunteers with the -assistance they need, is critical to reaching Project Gutenberg-tm's -goals and ensuring that the Project Gutenberg-tm collection will -remain freely available for generations to come. In 2001, the Project -Gutenberg Literary Archive Foundation was created to provide a secure -and permanent future for Project Gutenberg-tm and future generations. -To learn more about the Project Gutenberg Literary Archive Foundation -and how your efforts and donations can help, see Sections 3 and 4 -and the Foundation web page at http://www.pglaf.org. - - -Section 3. Information about the Project Gutenberg Literary Archive -Foundation - -The Project Gutenberg Literary Archive Foundation is a non profit -501(c)(3) educational corporation organized under the laws of the -state of Mississippi and granted tax exempt status by the Internal -Revenue Service. The Foundation's EIN or federal tax identification -number is 64-6221541. Its 501(c)(3) letter is posted at -http://pglaf.org/fundraising. Contributions to the Project Gutenberg -Literary Archive Foundation are tax deductible to the full extent -permitted by U.S. federal laws and your state's laws. - -The Foundation's principal office is located at 4557 Melan Dr. S. -Fairbanks, AK, 99712., but its volunteers and employees are scattered -throughout numerous locations. Its business office is located at -809 North 1500 West, Salt Lake City, UT 84116, (801) 596-1887, email -business@pglaf.org. Email contact links and up to date contact -information can be found at the Foundation's web site and official -page at http://pglaf.org - -For additional contact information: - Dr. Gregory B. Newby - Chief Executive and Director - gbnewby@pglaf.org - - -Section 4. Information about Donations to the Project Gutenberg -Literary Archive Foundation - -Project Gutenberg-tm depends upon and cannot survive without wide -spread public support and donations to carry out its mission of -increasing the number of public domain and licensed works that can be -freely distributed in machine readable form accessible by the widest -array of equipment including outdated equipment. Many small donations -($1 to $5,000) are particularly important to maintaining tax exempt -status with the IRS. - -The Foundation is committed to complying with the laws regulating -charities and charitable donations in all 50 states of the United -States. Compliance requirements are not uniform and it takes a -considerable effort, much paperwork and many fees to meet and keep up -with these requirements. We do not solicit donations in locations -where we have not received written confirmation of compliance. To -SEND DONATIONS or determine the status of compliance for any -particular state visit http://pglaf.org - -While we cannot and do not solicit contributions from states where we -have not met the solicitation requirements, we know of no prohibition -against accepting unsolicited donations from donors in such states who -approach us with offers to donate. - -International donations are gratefully accepted, but we cannot make -any statements concerning tax treatment of donations received from -outside the United States. U.S. laws alone swamp our small staff. - -Please check the Project Gutenberg Web pages for current donation -methods and addresses. Donations are accepted in a number of other -ways including checks, online payments and credit card donations. -To donate, please visit: http://pglaf.org/donate - - -Section 5. General Information About Project Gutenberg-tm electronic -works. - -Professor Michael S. Hart is the originator of the Project Gutenberg-tm -concept of a library of electronic works that could be freely shared -with anyone. For thirty years, he produced and distributed Project -Gutenberg-tm eBooks with only a loose network of volunteer support. - - -Project Gutenberg-tm eBooks are often created from several printed -editions, all of which are confirmed as Public Domain in the U.S. -unless a copyright notice is included. Thus, we do not necessarily -keep eBooks in compliance with any particular paper edition. - - -Most people start at our Web site which has the main PG search facility: - - http://www.gutenberg.org - -This Web site includes information about Project Gutenberg-tm, -including how to make donations to the Project Gutenberg Literary -Archive Foundation, how to help produce our new eBooks, and how to -subscribe to our email newsletter to hear about new eBooks. diff --git a/perl-practice/cli/argv.pl b/perl-practice/cli/argv.pl deleted file mode 100644 index 4f99b9b..0000000 --- a/perl-practice/cli/argv.pl +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; - -foreach my $a (@ARGV) { - printf("$a\n"); -} - -1; -__END__ diff --git a/perl-practice/cli/array_variables.pl b/perl-practice/cli/array_variables.pl deleted file mode 100644 index 7266a23..0000000 --- a/perl-practice/cli/array_variables.pl +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; - -my ($length, $width, $depth) = (10, 20, 15); - -print "The values are: ", $length, $width, $depth, "\n"; - -my ($name1, $name2, $name3, $name4) = ('Paul', 'Michael', 'Jessica', 'Megan'); - -print "Names are: $name1, $name2, $name3, $name4\n"; - -($name1, $name2, $name3, $name4) = qw/Paul Michael Jessica Megan/; - -print "Names are: $name1, $name2, $name3, $name4\n"; - -($name1, $name2, $name3, $name4) = qw(Paul Michael Jessica Megan); - -print "Names are: $name1, $name2, $name3, $name4\n"; - - -my @nums = (1, 2, 3, 4, 5); -print "\@nums=@nums\n"; -my @more = 6 .. 1000; -print "\@more=@more\n"; -my @none = (); -print "\@none=@none\n"; -my @names = qw/Paul Michael Jessica Megan/; -print "\@names=@names\n"; -my @all = (@nums, @more); -print "\@all=@all\n"; -my @nested = (@nums, \@more); -print "\@nested=@nested\n"; - -my $all_len = @all; -my $nested_len = @nested; - -print "\@all has length $all_len\n"; -print "\@nested has length $nested_len\n"; - - -my @array = (1, 2, 3, 4, 5); -print $array[0] . "\n"; -print $array[3] . "\n"; -print $array[-1] . "\n"; -print $array[4] . "\n"; -print $array[-1] . "\n"; -print $array[$#array] . "\n"; diff --git a/perl-practice/cli/datatypes.pl b/perl-practice/cli/datatypes.pl deleted file mode 100644 index ec27e31..0000000 --- a/perl-practice/cli/datatypes.pl +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; - -my $foo = 'foo'; -print "\$foo=$foo\n"; - -my @foo = (1, 2, 3); -print "\@foo=@foo\n"; - -my %foo = ( - 1 => 'one', - 2 => 'two', - 3 => 'three', -); -print "\%foo=" . %foo . "\n"; - -my $log = *STDIN; -print $log . "\n"; diff --git a/perl-practice/cli/ex01/a.pl b/perl-practice/cli/ex01/a.pl deleted file mode 100644 index e9761ae..0000000 --- a/perl-practice/cli/ex01/a.pl +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; - - -print "Hello world\n"; - - -1; -__END__ diff --git a/perl-practice/cli/ex01/b.pl b/perl-practice/cli/ex01/b.pl deleted file mode 100644 index 99c9503..0000000 --- a/perl-practice/cli/ex01/b.pl +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; - - -my $num = 4000 / 7; -print "$num\n"; - -print int($num + 0.005) . "\n"; - -printf("%.3f\n", $num); - -printf("00%.3f\n", $num); - - -sub show_signed { - my ($num) = @_; - if ($num gt 0) { - printf("+%.3f\n", $num); - } else { - printf("%.3f\n", $num); - } -} - -show_signed($num); -show_signed($num - 1000); - - -1; -__END__ diff --git a/perl-practice/cli/ex01/c.pl b/perl-practice/cli/ex01/c.pl deleted file mode 100644 index 52cbd37..0000000 --- a/perl-practice/cli/ex01/c.pl +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; - -use Math::Complex; - - -sub quad { - my ($a, $b, $c) = @_; - my $positive = ( - ($b * -1) - sqrt(($b ** 2) - (4 * ($a * $c))) / (2 * $a) - ); - my $negative = ( - ($b * -1) + sqrt(($b ** 2) - (4 * ($a * $c))) / (2 * $a) - ); - - return ($positive, $negative); -} - - -my @xx0 = quad(1, 2, 3); -printf("%s, %s\n", $xx0[0], $xx0[1]); - -my @xx1 = quad(4, 5, 6); -printf("%s, %s\n", $xx1[0], $xx1[1]); - -my @xx2 = quad(7, 8, 9); -printf("%s, %s\n", $xx2[0], $xx2[1]); - - -1; -__END__ diff --git a/perl-practice/cli/ex01/d.pl b/perl-practice/cli/ex01/d.pl deleted file mode 100644 index 0462989..0000000 --- a/perl-practice/cli/ex01/d.pl +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; - -use Math::Complex; - - -print "Entrez-vous\n"; - -my ($a, $b, $c) = (rand(100), rand(100), rand(100)); - -print "\$a=$a\n"; -print "\$b=$b\n"; -print "\$c=$c\n"; - - -sub quad { - my ($a, $b, $c) = @_; - my $positive = ( - ($b * -1) - sqrt(($b ** 2) - (4 * ($a * $c))) / (2 * $a) - ); - my $negative = ( - ($b * -1) + sqrt(($b ** 2) - (4 * ($a * $c))) / (2 * $a) - ); - - return ($positive, $negative); -} - - -my @result = quad($a, $b, $c); -printf("%s, %s\n", $result[0], $result[1]); - - -1; -__END__ - - - -1; -__END__ diff --git a/perl-practice/cli/ex02/input.pl b/perl-practice/cli/ex02/input.pl deleted file mode 100644 index b2e748a..0000000 --- a/perl-practice/cli/ex02/input.pl +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; - - -my @inlines = (); -my $i = 0; - -for ($i = 0; $i < 3; $i++) { - print "input please: "; - my $inline = ; - $inline =~ s/\s*$//; - $inlines[$i] = $inline; -} - - -print "You said:\n"; -print join("|", $inlines[0], $inlines[1], $inlines[2] . "\n"); - - -1; -__END__ diff --git a/perl-practice/cli/ex02/input_argv.pl b/perl-practice/cli/ex02/input_argv.pl deleted file mode 100644 index b410c2e..0000000 --- a/perl-practice/cli/ex02/input_argv.pl +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; - -foreach my $inline (@ARGV) { - print $inline . "\n"; -} - - -1; -__END__ diff --git a/perl-practice/cli/ex02/input_fromfile.pl b/perl-practice/cli/ex02/input_fromfile.pl deleted file mode 100644 index ee227fc..0000000 --- a/perl-practice/cli/ex02/input_fromfile.pl +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; - -use IO::File; -use File::Basename; - - -my $script = basename($0); -my $USAGE = < -USAGE -; - -if (!defined $ARGV[0]) { - die $USAGE; -} - -my $infile = $ARGV[0]; -open(DAT, $infile) or die "$infile: $!"; -my @cleaned = (); -foreach my $line () { - $line =~ s/\s*$//; - $cleaned[++$#cleaned] = $line; -} - -print join("|", @cleaned) . "\n"; - -close(DAT); - - -1; -__END__ diff --git a/perl-practice/cli/ex02/quadratic.pl b/perl-practice/cli/ex02/quadratic.pl deleted file mode 100644 index 09fb617..0000000 --- a/perl-practice/cli/ex02/quadratic.pl +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; - -use Math::Complex; -use File::Basename; - - -my $prog = basename($0); -my $USAGE = < -USAGE -; - - -sub quad { - my ($a, $b, $c) = @_; - my $positive = ( - ($b * -1) - sqrt(($b ** 2) - (4 * ($a * $c))) / (2 * $a) - ); - my $negative = ( - ($b * -1) + sqrt(($b ** 2) - (4 * ($a * $c))) / (2 * $a) - ); - - return ($positive, $negative); -} - -foreach my $arg (@ARGV) { - if (($arg eq "-h") || ($arg eq "--help")) { - die $USAGE; - } -} - -my ($a, $b, $c) = @ARGV; -if (!defined $a) { - print '$a = '; - $a = ; -} -if (!defined $b) { - print '$b = '; - $b = ; -} -if (!defined $c) { - print '$c = '; - $c = ; -} - -my @result = quad($a, $b, $c); -printf("%s, %s\n", $result[0], $result[1]); - - -1; -__END__ diff --git a/perl-practice/cli/ex03/rwfakegrep.pl b/perl-practice/cli/ex03/rwfakegrep.pl deleted file mode 100644 index 16cf4ea..0000000 --- a/perl-practice/cli/ex03/rwfakegrep.pl +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; - -use File::Basename; -use English qw/$PROGRAM_NAME/; - -my $basename = basename($0); -my $USAGE = < -USAGE -; - - -sub show_last_chapter_with_nlines { - my ($ch, $nlines) = @_; - print "Chapter $ch has $nlines lines\n"; -} - - -sub main { - open(INFILE, '<', $ARGV[0]) or die "$USAGE\n$!"; - open(OUTFILE, '>', $ARGV[1]) or die "$USAGE\n$!"; - - my $have_seen_firstchapter = 'no'; - my $nlines = 0; - my $chline = ''; - my $ch = ''; - - foreach my $inline () { - if ($inline =~ /^\s*CHAPTER.*$/) { - - $chline = "$inline"; - $ch = "$chline"; - $ch =~ s/^\s*CHAPTER\s*([0-9]*).*/$1/; - $ch =~ s/[\r\n]//; - - if ($have_seen_firstchapter eq 'yes') { - show_last_chapter_with_nlines($ch - 1, $nlines); - $nlines = 0; - } else { - $have_seen_firstchapter = 'yes'; - $nlines = 0; - } - print OUTFILE $inline; - } - $nlines++; - } - - show_last_chapter_with_nlines($ch, $nlines); - -} - - -if ($PROGRAM_NAME eq __FILE__) { - main(); -} - - -1; -__END__ diff --git a/perl-practice/cli/ex03/rwfiles.pl b/perl-practice/cli/ex03/rwfiles.pl deleted file mode 100644 index eaef5ec..0000000 --- a/perl-practice/cli/ex03/rwfiles.pl +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; - -use File::Basename; - -my $basename = basename($0); -my $USAGE = < -USAGE -; - -open(INFILE, '<', $ARGV[0]) or die "$USAGE\n$!"; -open(OUTFILE, '>', $ARGV[1]) or die "$USAGE\n$!"; - -foreach my $inline () { - print OUTFILE $inline; -} - - - -1; -__END__ diff --git a/perl-practice/cli/filehandles.pl b/perl-practice/cli/filehandles.pl deleted file mode 100644 index 26f1d24..0000000 --- a/perl-practice/cli/filehandles.pl +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use IO::File; -use Data::Dumper; - -open(my $fh, '<', 'foo.txt'); - -my @lines = <$fh>; - -print Data::Dumper->Dump([\@lines], [qw(lines)]); - - -open(my $fh2, '<', 'foo.txt'); - -while(my $line = <$fh2>) { - print $line; -} - - -my $fh3 = IO::File->new('foo.txt', 'r'); - -while(my $line = $fh3->getline()) { - print $line; -} - - -my $fh4 = IO::File->new('foo.txt', 'r'); -my @lines4 = $fh4->getlines(); - -print @lines4; -print Data::Dumper->Dump([\@lines4], [qw(lines)]); - - -1; -__END__ diff --git a/perl-practice/cli/foo.txt b/perl-practice/cli/foo.txt deleted file mode 100644 index ec5e80f..0000000 --- a/perl-practice/cli/foo.txt +++ /dev/null @@ -1,6 +0,0 @@ -these -runes -are -dusty -sir -? diff --git a/perl-practice/cli/functions.pl b/perl-practice/cli/functions.pl deleted file mode 100644 index c7fe297..0000000 --- a/perl-practice/cli/functions.pl +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; - -sub print_error_message { - my ($message) = @_; - print STDOUT "ERROR: " . $message . "!!!\n"; -} - - -print_error_message("something bad happened"); -print_error_message("something really horrible happened"); -print_error_message("something sort of annoying happened"); - - -sub add_two_numbers { - my ($x, $y) = @_; - my $sum = $x + $y; - return $sum; -} - -print add_two_numbers(3, 4) . "\n"; -print add_two_numbers(5, 6) . "\n"; -print add_two_numbers(7, 8) . "\n"; - - -sub add_two_numbers_and_mult_by_three { - my ($x, $y) = @_; - my $sum = add_two_numbers($x, $y); - my $sum_times_three = $sum * 3; - return $sum_times_three; -} - -print add_two_numbers_and_mult_by_three(3, 4) . "\n"; -print add_two_numbers_and_mult_by_three(5, 6) . "\n"; -print add_two_numbers_and_mult_by_three(7, 8) . "\n"; - - -sub factorial { - my ($num) = @_; - if ($num == 1) { - return 1; - } else { - return $num * factorial($num - 1); - } -} - -foreach my $n (1 .. 10) { - print factorial($n) . "\n"; -} - - -1; -__END__ diff --git a/perl-practice/cli/hash_variables.pl b/perl-practice/cli/hash_variables.pl deleted file mode 100644 index 4ee1a84..0000000 --- a/perl-practice/cli/hash_variables.pl +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use Data::Dumper; - - -my %petsounds = ( - "cat" => "meow", - "dog" => "woof", - "snake" => "hiss" -); - - -print "The cat goes " . $petsounds{"cat"} . ".\n"; - - -$petsounds{"mouse"} = "squeak!"; -$petsounds{"dog"} = "arf!"; - - -delete($petsounds{"cat"}); - - -print "The mouse goes " . $petsounds{"mouse"} . ".\n"; - - -print Dumper(\%petsounds) . "\n"; - - -my %a = (); -$a{1}{"a"}{"A"} = "FIRST"; -$a{1}{"c"}{"B"} = "THIRD"; -$a{1}{"b"}{"C"} = "SECOND"; - -foreach my $k1 (sort keys %a) { - foreach my $k2 (sort keys %{$a{$k1}}) { - foreach my $k3 (sort keys %{$a{$k1}{$k2}}) { - print "$k1\t$k2\t$k3\t$a{$k1}{$k2}{$k3}\n"; - } - } -} - -print Dumper(\%a); - - -1; -__END__ diff --git a/perl-practice/cli/heredoc.pl b/perl-practice/cli/heredoc.pl deleted file mode 100644 index 26d8abf..0000000 --- a/perl-practice/cli/heredoc.pl +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/perl - -print < 1, - ho => 2, - he => 3, -); - -if ($scalar ~~ @array) { - print "scalar matches array\n"; -} -if ($scalar ~~ %hash) { - print "scalar matches hash\n"; -} -if (@array ~~ %hash) { - print "array matches hash\n"; -} diff --git a/perl-practice/cli/quoting.pl b/perl-practice/cli/quoting.pl deleted file mode 100644 index 121adc8..0000000 --- a/perl-practice/cli/quoting.pl +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; - - -print qq{I said "They're the most delicious fruits!".\n}; -print q/I said "They're the most delicious fruits!"./ . "\n"; - - -print <; -$name =~ s/\n//; - -print "Your name is $name\n"; - - -1; -__END__ diff --git a/perl-practice/cli/string_operators.pl b/perl-practice/cli/string_operators.pl deleted file mode 100644 index a7eb8af..0000000 --- a/perl-practice/cli/string_operators.pl +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/perl - -print "Hello" . "World\n"; -print "Hello" . " " . "World\n"; - -print "Hello" x 5, "\n"; diff --git a/perl-practice/cli/variables.pl b/perl-practice/cli/variables.pl deleted file mode 100644 index 00577cf..0000000 --- a/perl-practice/cli/variables.pl +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; - -my $firstname = "Jonathan"; - -print "Hello, $firstname\n"; - -$firstname = "John"; - -print "Goodbye, $firstname\n"; - - -my $variable = "\0"; -my $another_variable = 2; -my @array_variable = qw(one two three); - -$variable = 3; -print "$variable\n"; -$variable = 3.1415926; -print "$variable\n"; -$variable = 3.402823669209384634633e+38; -print "$variable\n"; -$variable = $another_variable + 1; -print "$variable\n"; -$variable = 'Can contain text'; -print "$variable\n"; -$variable = \$another_variable; -print "$variable\n"; -$variable = \@array_variable; -print "$variable\n"; - - -my @Array1 = (1, 2, 3); -my @Array2 = (4, 5, 6); -my @Array3 = (7, 8, 9); - -@array_variable = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10); -print "@array_variable\n"; -@array_variable = (1 .. 10); -print "@array_variable\n"; -@array_variable = ('John', 'Paul', 'George', 'Ringo'); -print "@array_variable\n"; -@array_variable = qw/John Paul George Ringo/; -print "@array_variable\n"; -@array_variable = qw/red blue 1 green 5/; -print "@array_variable\n"; -@array_variable = (\@Array1, \@Array2, \@Array3); -print "@array_variable\n"; - -my $idx = 2; - -$array_variable[0] = 1; -print "@array_variable\n"; -$array_variable[$idx] = 1; -print "@array_variable\n"; - -my %hash = ( - 'key1' => 'value1', - 'key2' => 'value2', - 'key3' => 'value3', -); -print %hash, "\n"; - -$hash{'key1'} = 'newval1'; -print %hash, "\n"; - - -sub fib { - my $n = shift(); - return $n if $n < 2; - return fib($n - 1) + fib($n - 2); -} - -print fib(14), "\n"; diff --git a/perl-practice/web/Makefile b/perl-practice/web/Makefile deleted file mode 100644 index c3234cc..0000000 --- a/perl-practice/web/Makefile +++ /dev/null @@ -1,39 +0,0 @@ - -ROOT ?= $(PWD) -HTTP_PORT ?= 49228 -NGINX_CONF_IN := nginx.conf.in -ALL_NGINX_CONF_INPUTS := \ - $(NGINX_CONF_IN) \ - $(wildcard perl_requirements.d/*) \ - $(wildcard perl_locations.d/*) - - -serve-lighttpd: lighttpd.conf - lighttpd -D -f $(ROOT)/$< - - -serve-nginx: nginx.conf - nginx -p $(ROOT)/ -c $(ROOT)/$< - - -nginx.conf: $(ALL_NGINX_CONF_INPUTS) - cat $< | \ - sed -e 's@__ROOT__@$(ROOT)@g' \ - -e 's@__HTTP_PORT__@$(HTTP_PORT)@g' > $@ - - -lighttpd.conf: lighttpd.conf.in - cat $< | \ - sed -e 's@__ROOT__@$(ROOT)@g' \ - -e 's@__HTTP_PORT__@$(HTTP_PORT)@g' > $@ - - -serve-cgiwrap: cgiwrap-fcgi.pl - perl $< - - -cgiwrap-fcgi.pl: cgiwrap-fcgi.pl.in - cat $< | sed -e 's@__ROOT__@$(ROOT)@g' > $@ - - -.PHONY: serve-nginx serve-lighttpd serve-cgiwrap diff --git a/perl-practice/web/cgiwrap-fcgi.pl.in b/perl-practice/web/cgiwrap-fcgi.pl.in deleted file mode 100644 index 09355fc..0000000 --- a/perl-practice/web/cgiwrap-fcgi.pl.in +++ /dev/null @@ -1,155 +0,0 @@ -#!/usr/bin/env perl - -use FCGI; -use Socket; -use FCGI::ProcManager; -sub shutdown { FCGI::CloseSocket($socket); exit; } -sub restart { FCGI::CloseSocket($socket); &main; } -use sigtrap 'handler', \&shutdown, 'normal-signals'; -use sigtrap 'handler', \&restart, 'HUP'; -require 'syscall.ph'; -use POSIX qw(setsid); - -END() { } -BEGIN() { } -{ - no warnings; - *CORE::GLOBAL::exit = sub { die "fakeexit\nrc=" . shift() . "\n"; }; -}; - -eval q{exit}; -if ($@) { - exit unless $@ =~ /^fakeexit/; -} -&main; - -sub daemonize() { - chdir '/' or die "Can't chdir to /: $!"; - defined( my $pid = fork ) or die "Can't fork: $!"; - exit if $pid; - setsid() or die "Can't start a new session: $!"; - umask 0; -} - -sub main { - $proc_manager = FCGI::ProcManager->new( {n_processes => 5} ); - $socket = FCGI::OpenSocket("__ROOT__/nginx-cgiwrap-dispatch.sock", 10 ) - ; #use UNIX sockets - user running this script must have w access to the 'nginx' folder!! - $request = - FCGI::Request( \*STDIN, \*STDOUT, \*STDERR, \%req_params, $socket, - &FCGI::FAIL_ACCEPT_ON_INTR ); - $proc_manager->pm_manage(); - if ($request) { request_loop() } - FCGI::CloseSocket($socket); -} - -sub request_loop { - while ( $request->Accept() >= 0 ) { - $proc_manager->pm_pre_dispatch(); - - #processing any STDIN input from WebServer (for CGI-POST actions) - $stdin_passthrough = ''; - { no warnings; $req_len = 0 + $req_params{'CONTENT_LENGTH'}; }; - if ( ( $req_params{'REQUEST_METHOD'} eq 'POST' ) && ( $req_len != 0 ) ) { - my $bytes_read = 0; - while ( $bytes_read < $req_len ) { - my $data = ''; - my $bytes = read( STDIN, $data, ( $req_len - $bytes_read ) ); - last if ( $bytes == 0 || !defined($bytes) ); - $stdin_passthrough .= $data; - $bytes_read += $bytes; - } - } - - #running the cgi app - if ( - ( -x $req_params{SCRIPT_FILENAME} ) && #can I execute this? - ( -s $req_params{SCRIPT_FILENAME} ) && #Is this file empty? - ( -r $req_params{SCRIPT_FILENAME} ) #can I read this file? - ) { - pipe( CHILD_RD, PARENT_WR ); - pipe( PARENT_ERR, CHILD_ERR ); - my $pid = open( CHILD_O, "-|" ); - unless ( defined($pid) ) { - print("Content-type: text/plain\r\n\r\n"); - print "Error: CGI app returned no output - Executing $req_params{SCRIPT_FILENAME} failed !\n"; - next; - } - $oldfh = select(PARENT_ERR); - $| = 1; - select(CHILD_O); - $| = 1; - select($oldfh); - if ( $pid > 0 ) { - close(CHILD_RD); - close(CHILD_ERR); - print PARENT_WR $stdin_passthrough; - close(PARENT_WR); - $rin = $rout = $ein = $eout = ''; - vec( $rin, fileno(CHILD_O), 1 ) = 1; - vec( $rin, fileno(PARENT_ERR), 1 ) = 1; - $ein = $rin; - $nfound = 0; - - while ( $nfound = select( $rout = $rin, undef, $ein = $eout, 10 ) ) { - die "$!" unless $nfound != -1; - $r1 = vec( $rout, fileno(PARENT_ERR), 1 ) == 1; - $r2 = vec( $rout, fileno(CHILD_O), 1 ) == 1; - $e1 = vec( $eout, fileno(PARENT_ERR), 1 ) == 1; - $e2 = vec( $eout, fileno(CHILD_O), 1 ) == 1; - - if ($r1) { - while ( $bytes = read( PARENT_ERR, $errbytes, 4096 ) ) { - print STDERR $errbytes; - } - if ($!) { - $err = $!; - die $!; - vec( $rin, fileno(PARENT_ERR), 1 ) = 0 - unless ( $err == EINTR or $err == EAGAIN ); - } - } - if ($r2) { - while ( $bytes = read( CHILD_O, $s, 4096 ) ) { - print $s; - } - if ( !defined($bytes) ) { - $err = $!; - die $!; - vec( $rin, fileno(CHILD_O), 1 ) = 0 - unless ( $err == EINTR or $err == EAGAIN ); - } - } - last if ( $e1 || $e2 ); - } - close CHILD_RD; - close PARENT_ERR; - waitpid( $pid, 0 ); - } else { - foreach $key ( keys %req_params ) { - $ENV{$key} = $req_params{$key}; - } - - # cd to the script's local directory - if ( $req_params{SCRIPT_FILENAME} =~ /^(.*)\/[^\/] +$/ ) { - chdir $1; - } - close(PARENT_WR); - #close(PARENT_ERR); - close(STDIN); - close(STDERR); - - #fcntl(CHILD_RD, F_DUPFD, 0); - syscall( &SYS_dup2, fileno(CHILD_RD), 0 ); - syscall( &SYS_dup2, fileno(CHILD_ERR), 2 ); - - #open(STDIN, "<&CHILD_RD"); - exec( $req_params{SCRIPT_FILENAME} ); - die("exec failed"); - } - } else { - print("Content-type: text/plain\r\n\r\n"); - print "Error: No such CGI app - $req_params{SCRIPT_FILENAME} may not exist or is not executable by this process.\n"; - } - } -} diff --git a/perl-practice/web/fastcgi_params b/perl-practice/web/fastcgi_params deleted file mode 100644 index d1862e9..0000000 --- a/perl-practice/web/fastcgi_params +++ /dev/null @@ -1,19 +0,0 @@ -fastcgi_param GATEWAY_INTERFACE CGI/1.1; -fastcgi_param SERVER_SOFTWARE nginx; -fastcgi_param QUERY_STRING $query_string; -fastcgi_param REQUEST_METHOD $request_method; -fastcgi_param CONTENT_TYPE $content_type; -fastcgi_param CONTENT_LENGTH $content_length; -fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; -fastcgi_param SCRIPT_NAME $fastcgi_script_name; -fastcgi_param REQUEST_URI $request_uri; -fastcgi_param DOCUMENT_URI $document_uri; -fastcgi_param DOCUMENT_ROOT $document_root; -fastcgi_param SERVER_PROTOCOL $server_protocol; -fastcgi_param REMOTE_ADDR $remote_addr; -fastcgi_param REMOTE_PORT $remote_port; -fastcgi_param SERVER_ADDR $server_addr; -fastcgi_param SERVER_PORT $server_port; -fastcgi_param SERVER_NAME $server_name; - -# vim:filetype=nginx diff --git a/perl-practice/web/html/cgi-bin/query.cgi b/perl-practice/web/html/cgi-bin/query.cgi deleted file mode 100755 index 949c018..0000000 --- a/perl-practice/web/html/cgi-bin/query.cgi +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env perl - -use strict; -use warnings; -use CGI; -use CGI::Carp qw(carpout fatalsToBrowser); - - -BEGIN { - use CGI::Carp qw(carpout); - open(LOG, ">>/home/me/tmp/mycgi-log") or - die("Unable to open mycgi-log: $!\n"); - carpout(*LOG); -} - - -sub main { - my $query = CGI->new(); - print $query->header(-content_type => 'text/plain'); - - my $search = $query->param('q'); - - if (!$search eq undef) { - printf("You searched for: %s\n", $query->escapeHTML($search)); - } else { - printf("Invalid search? You must provide a 'q' argument.\n"); - } -} - - -main(); - - -1; -__END__ diff --git a/perl-practice/web/html/cgi-bin/test.cgi b/perl-practice/web/html/cgi-bin/test.cgi deleted file mode 100755 index fa8f09b..0000000 --- a/perl-practice/web/html/cgi-bin/test.cgi +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env perl - -printf("Content-Type: text/plain\n\n"); -printf("Hello Test\n"); - -1; -__END__ diff --git a/perl-practice/web/lib/perl/base.pm b/perl-practice/web/lib/perl/base.pm deleted file mode 100644 index 52d3d74..0000000 --- a/perl-practice/web/lib/perl/base.pm +++ /dev/null @@ -1,38 +0,0 @@ -package base; - -use strict; -use warnings; -use nginx; - - -sub handler { - my $r = shift(); - - $r->send_http_header("text/plain"); - return OK if $r->header_only(); - - $r->print("Hello There!\n"); - $r->rflush(); - - if (-f $r->filename or -d _) { - $r->print($r->uri, " exists!\n"); - } else { - $r->print($r->uri, " does not exist!\n"); - } - - my $directory = '/home/me/tmp'; - # '/home/me/src/LearningPerl/src/web'; - - my $didopen = opendir(DIR, $directory); - if ($didopen) { - while (my $file = readdir(DIR)) { - $r->print("$file\n"); - } - - closedir(DIR); - } -} - - -1; -__END__ diff --git a/perl-practice/web/lighttpd.conf.in b/perl-practice/web/lighttpd.conf.in deleted file mode 100644 index 877d00f..0000000 --- a/perl-practice/web/lighttpd.conf.in +++ /dev/null @@ -1,119 +0,0 @@ -## modules to load -server.modules = ( - "mod_alias", - "mod_compress", - "mod_cgi", -# "mod_rewrite", -# "mod_redirect", -# "mod_usertrack", -# "mod_expire", -# "mod_flv_streaming", -# "mod_evasive" -) - -## a static document-root, for virtual-hosting take look at the -## server.virtual-* options -server.document-root = "__ROOT__/html" - -## where to upload files to, purged daily. -server.upload-dirs = ("__ROOT__/lighttpd-uploads") - -## where to send error-messages to -server.errorlog = "__ROOT__/lighttpd-error.log" - -## files to check for if .../ is requested -index-file.names = ( - "index.php", - "index.cgi", - "index.py", - "index.pl", - "index.html", - "index.htm", - "default.htm", - "index.lighttpd.html", -) - -## Use the "Content-Type" extended attribute to obtain mime type if possible -# mimetype.use-xattr = "enable" - -## -# which extensions should not be handle via static-file transfer -# -# .php, .pl, .fcgi are most often handled by mod_fastcgi or mod_cgi -static-file.exclude-extensions = (".php", ".pl", ".fcgi") - - -cgi.assign = ( - ".pl" => "/usr/bin/perl", - ".php" => "/usr/bin/php-cgi", - ".py" => "/usr/bin/python", -) - - -$HTTP["url"] =~ "^/cgi-bin/" { - cgi.assign += ("" => "") -} - - - - - -######### Options that are good to be but not neccesary to be changed ####### - -## Use ipv6 only if available. (disabled for while, check #560837) -#include_shell "/usr/share/lighttpd/use-ipv6.pl" - -## bind to port (default: 80) -server.port = __HTTP_PORT__ - -## bind to localhost only (default: all interfaces) -server.bind = "localhost" - -## error-handler for status 404 -#server.error-handler-404 = "/error-handler.html" -#server.error-handler-404 = "/error-handler.php" - -## to help the rc.scripts -server.pid-file = "__ROOT__/lighttpd.pid" - -## -## Format: .html -## -> ..../status-404.html for 'File not found' -#server.errorfile-prefix = "/var/www/" - -## virtual directory listings -dir-listing.encoding = "utf-8" -server.dir-listing = "enable" - -### only root can use these options -# -# chroot() to directory (default: no chroot() ) -#server.chroot = "/" - -## change uid to (default: don't change) -# server.username = "www-data" - -## change gid to (default: don't change) -# server.groupname = "www-data" - -#### compress module -compress.cache-dir = "__ROOT__/lighttpd-compress/" -compress.filetype = ("text/plain", "text/html", "application/x-javascript", "text/css") - -#### url handling modules (rewrite, redirect, access) -# url.rewrite = ( "^/$" => "/server-status" ) -# url.redirect = ( "^/wishlist/(.+)" => "http://www.123.org/$1" ) - -#### expire module -# expire.url = ( "/buggy/" => "access 2 hours", "/asdhas/" => "access plus 1 seconds 2 minutes") - -#### external configuration files -## mimetype mapping -include_shell "/usr/share/lighttpd/create-mime.assign.pl" - -## load enabled configuration files, -## read /etc/lighttpd/conf-available/README first -# include_shell "/usr/share/lighttpd/include-conf-enabled.pl" - - -# vim:filetype=lighttpd diff --git a/perl-practice/web/mime.types b/perl-practice/web/mime.types deleted file mode 100644 index 808160d..0000000 --- a/perl-practice/web/mime.types +++ /dev/null @@ -1,71 +0,0 @@ - -types { - text/html html htm shtml; - text/css css; - text/xml xml rss; - image/gif gif; - image/jpeg jpeg jpg; - application/x-javascript js; - application/atom+xml atom; - - text/mathml mml; - text/plain txt; - text/vnd.sun.j2me.app-descriptor jad; - text/vnd.wap.wml wml; - text/x-component htc; - - image/png png; - image/tiff tif tiff; - image/vnd.wap.wbmp wbmp; - image/x-icon ico; - image/x-jng jng; - image/x-ms-bmp bmp; - image/svg+xml svg svgz; - - application/java-archive jar war ear; - application/mac-binhex40 hqx; - application/msword doc; - application/pdf pdf; - application/postscript ps eps ai; - application/rtf rtf; - application/vnd.ms-excel xls; - application/vnd.ms-powerpoint ppt; - application/vnd.wap.wmlc wmlc; - application/vnd.wap.xhtml+xml xhtml; - application/x-7z-compressed 7z; - application/x-cocoa cco; - application/x-java-archive-diff jardiff; - application/x-java-jnlp-file jnlp; - application/x-makeself run; - application/x-perl pl pm; - application/x-pilot prc pdb; - application/x-rar-compressed rar; - application/x-redhat-package-manager rpm; - application/x-sea sea; - application/x-shockwave-flash swf; - application/x-stuffit sit; - application/x-tcl tcl tk; - application/x-x509-ca-cert der pem crt; - application/x-xpinstall xpi; - application/zip zip; - - application/octet-stream bin exe dll; - application/octet-stream deb; - application/octet-stream dmg; - application/octet-stream eot; - application/octet-stream iso img; - application/octet-stream msi msp msm; - - audio/midi mid midi kar; - audio/mpeg mp3; - audio/x-realaudio ra; - - video/3gpp 3gpp 3gp; - video/mpeg mpeg mpg; - video/quicktime mov; - video/x-flv flv; - video/x-mng mng; - video/x-ms-asf asx asf; - video/x-ms-wmv wmv; - video/x-msvideo avi; -} diff --git a/perl-practice/web/nginx.conf.in b/perl-practice/web/nginx.conf.in deleted file mode 100644 index fb04cc7..0000000 --- a/perl-practice/web/nginx.conf.in +++ /dev/null @@ -1,63 +0,0 @@ -worker_processes 1; -error_log __ROOT__/error.log; -pid __ROOT__/server.pid; -daemon off; - - -events { - worker_connections 4096; -} - - -http { - include __ROOT__/mime.types; - - perl_modules __ROOT__/lib/perl; - include __ROOT__/perl_requirements.d/*; - - default_type application/octet-stream; - log_format main '$remote_addr - $remote_user [$time_local] $status ' - '"$request" $body_bytes_sent "$http_referer" ' - '"$http_user_agent" "$http_x_forwarded_for"'; - sendfile on; - tcp_nopush on; - autoindex on; - - server { - root __ROOT__/html; - index index.html; - - listen __HTTP_PORT__; - server_name localhost; - access_log __ROOT__/access.log main; - - include __ROOT__/perl_locations.d/*; - - location ~ ^/cgi-bin/.*\.cgi$ { - gzip off; - fastcgi_pass unix:__ROOT__/nginx-cgiwrap-dispatch.sock; - fastcgi_index index.cgi; - fastcgi_param SCRIPT_FILENAME __ROOT__/html$fastcgi_script_name; - fastcgi_param QUERY_STRING $query_string; - fastcgi_param REQUEST_METHOD $request_method; - fastcgi_param CONTENT_TYPE $content_type; - fastcgi_param CONTENT_LENGTH $content_length; - fastcgi_param GATEWAY_INTERFACE CGI/1.1; - fastcgi_param SERVER_SOFTWARE nginx; - fastcgi_param SCRIPT_NAME $fastcgi_script_name; - fastcgi_param REQUEST_URI $request_uri; - fastcgi_param DOCUMENT_URI $document_uri; - fastcgi_param DOCUMENT_ROOT $document_root; - fastcgi_param SERVER_PROTOCOL $server_protocol; - fastcgi_param REMOTE_ADDR $remote_addr; - fastcgi_param REMOTE_PORT $remote_port; - fastcgi_param SERVER_ADDR $server_addr; - fastcgi_param SERVER_PORT $server_port; - fastcgi_param SERVER_NAME $server_name; - } - } - -} - - -# vim:filetype=nginx diff --git a/perl-practice/web/perl_locations.d/base.conf b/perl-practice/web/perl_locations.d/base.conf deleted file mode 100644 index 4e887de..0000000 --- a/perl-practice/web/perl_locations.d/base.conf +++ /dev/null @@ -1,5 +0,0 @@ -location /embedded { - perl base::handler; -} - -# vim:filetype=nginx diff --git a/perl-practice/web/perl_requirements.d/base.conf b/perl-practice/web/perl_requirements.d/base.conf deleted file mode 100644 index 8d7663e..0000000 --- a/perl-practice/web/perl_requirements.d/base.conf +++ /dev/null @@ -1 +0,0 @@ -perl_require base.pm; diff --git a/r-practice/README.tex b/r-practice/README.tex deleted file mode 100644 index 731ecc7..0000000 --- a/r-practice/README.tex +++ /dev/null @@ -1,6 +0,0 @@ -\begin{document} -\section{Practicing R} - -Where I practice and learn and destroy me some R. - -\end{document} diff --git a/r-practice/README.txt b/r-practice/README.txt deleted file mode 100644 index 4c1471d..0000000 --- a/r-practice/README.txt +++ /dev/null @@ -1,6 +0,0 @@ - -Practicing R - -Where I practice and learn and destroy me some R. - - diff --git a/r-practice/elementary-statistics/.RData b/r-practice/elementary-statistics/.RData deleted file mode 100644 index 571f78b..0000000 Binary files a/r-practice/elementary-statistics/.RData and /dev/null differ diff --git a/r-practice/elementary-statistics/.Rhistory b/r-practice/elementary-statistics/.Rhistory deleted file mode 100644 index f80727a..0000000 --- a/r-practice/elementary-statistics/.Rhistory +++ /dev/null @@ -1,367 +0,0 @@ -library(MASS) -painters -painters$School -school = painters$School -school.freq = table(school) -school.freq -cbind(school.freq) -head(painters) -composition = painters$Composition -composition.freq = table(composition) -cbind(composition.freq) -school -school.freq -school.freq[1] -help(max) -school[,][1] -school[1,][1] -school[1][1] -school[1] -school.freq[1,] -school.freq[1] -school.freq[1][1] -school.freq[1] -help(typeof) -typeof(school.freq[1]) -max(school.freq) -max(school) -max(school.freq) -school.relfreq = school.freq / nrow(painters) -school.relfreq -settings = options(digits=1) -school.relfreq -options(settings) -cbind(school.relfreq) -composition.freq -composition.relfreq = composition.freq / nrow(composition) -composition.relfreq = composition.freq / nrow(painters) -composition.relfreq -cbind(composition.relfreq) -# bar graph exercise -library(MASS) -school = painters$School -school.freq = table(school) -barplot(school.freq) -colors = c("red", "yellow", "green", "violet", "orange", "blue", "pink", "cyan") -barplot(schools.freq, col=colors) -barplot(school.freq, col=colors) -composition = painters$Composition -composition.freq = table(composition) -count.fields(composition.freq) -ncol(composition.freq) -composition.freq -nrow(composition.freq) -nrow(school.freq) -colors -barplot(composition.freq, col=colors) -q() -library(MASS) -school = painters$school -school -school = painters$School -school -school.freq = table(school) -pip(school.freq) -pie(school.freq) -colors = c("red", "yellow", "green", "violet", "orange", "blue", "pink", "cyan") -pie(school.freq, col=colors) -composition = painters$Composition -composition.freq = table(composition) -pip(composition.freq, col=colors) -pie(composition.freq, col=colors) -library(MASS) -school = painters$School -c_school = school == "C" -c_painters = painters[c_school,] -mean(c_painters$Composition) -pie(tapply(painters$Composition, painters$School, mean) -pie(tapply(painters$Composition, painters$School, mean)) -barchart(tapply(painters$Composition, painters$School, mean)) -barplot(tapply(painters$Composition, painters$School, mean)) -q() -head(faithful) -duration = faithful$eruptions -range(duration) -breaks = seq(1.5, 5.5, by=0.5) -breaks -duration.cut = cut(duration, breaks, right=FALSE) -duration.freq = table(duration.cut) -duration.freq -cbind(duration.freq) -barplot(duration.freq) -nrow(faithful) -faithful$eruptions / nrow(faithful) -help(hist) -hist(faithful$eruptions) -faithful) -head(faithful) -hist(faithful$waiting) -hist(faithful) -help(barplot) -VADeaths -help(demo) -demo() -demo("graphics") -hist(faithful$waiting) -interval = faithful$waiting -interval -range(interval) -breaks = seq(43, 96, by=1) -breaks -interval.cut = cut(interval, breaks, right=FALSE) -interval.freq = table(interval.cut) -barplot(interval.freq) -breaks = seq(43, 96, by=5) -breaks -interval.cut = cut(interval, breaks, right=FALSE) -interval.freq = table(interval.cut) -barplot(interval.freq) -help(points) -points(interval.freq) -barplot(interval.freq) -hist(faithful$eruptions, right=FALSE) -duration = faithful$eruptions -hist(duration, right=FALSE) -colors = c("red", "yellow", "green", "violet", "orange", "blue", "pink", "cyan") -hist(duration, right=FALSE, col=colors, main="Old Faithful Eruptions", xlab="Duration minutes") -waiting_period = faithful$waiting -waiting_period = faithful$waiting -hist(waiting_period, right=FALSE, col=colors, main="Old Faithful Eruptions", xlab="Interval") -hist(waiting_period, right=FALSE, col=colors, main="Old Faithful Eruptions", xlab="Interval in minutes") -q() -duration = faithful$eruptions -breaks = seq(1.5, 5.5, by=0.5) -duration.cut = cut(duration, breaks, right=FALSE) -duration.freq = table(duration.cut) -duration.relfreq = duration.freq / nrow(faithful) -duration.relfreq -pie(duration.relfreq) -hist(duration.relfreq) -hist(duration.relfreq) -duration.freq -duration = faithful$eruptions -breaks = seq(1.5, 5.5, by=0.5) -breaks -typeof(breaks) -duration.cut = cut(duration, breaks, right=FALSE) -duration.freq = table(duration.cut) -duration.cumfreq = cumsum(duration.freq) -duration.cumfreq -hist(cbind(duration.cumfreq)) -interval = faithful$waiting -help(function) -help("function") -help("function") -calc_cumfreq <- function(records) - breaks = seq(1.5, 5.5, by=0.5) - records.cut = cut(duration, breaks, right=FALSE) - records.freq = table(duration.cut) - records.cumfreq = cumsum(records.freq) -return(records) -calc_cumfreq <- function(records) - breaks = seq(1.5, 5.5, by=0.5) - records.cut = cut(records, breaks, right=FALSE) -help("function") -duration.cumfreq -interval = faithful$eruptions -breaks -breaks.cut = cut(interval, breaks, right=FALSE) -interval.freq = table(interval.cut) -interval.cumfreq = cumsum(interval.freq) -hist(interval.cumfreq) -q() -duration = faithful$eruptions -breaks = seq(1.5, 5.5, by=0.5) -duration.cut = cut(duration, breaks, right=FALSE) -duration.freq = table(duration.cut) -cumfreq0 = c(0, cumsum(duration.freq)) -plot(breaks, cumfreq0, main="Old Faithful Eruptions", xlab="Duration minutes", ylab="Cumulative Eruptions") -lines(breaks, cumfreq0) -intervals = faithful$waiting -faithful$waiting -cbind(faithful$waiting) -faithful$waiting / nrow(faithful) -faithful$waiting / nrow(faithful$waiting) -intervals -breaks -intervals.cut = cut(breaks, intervals) -help(cut) -intervals.cut = cut(intervals, breaks) -intervals.cut -intervals.cut -intervals.freq = table(intervals.cut) -intervals.cut = cut(intervals, breaks, right=FALSE) -intervals.freq = table(intervals.cut) -cumfreq0 = c(0, cumsum(intervals.freq)) -cumfreq0 -intervals -intervals.cut = cut(intervals, breaks, right=FALSE) -intervals.cut -intervals.freq = table(intervals.cut) -intervals.freq -cbind(intervals.freq) -plot(breaks, cumfreq0) -intervals -cut(intervals, breaks) -cut(intervals, breaks, right=FALSE) -duration -cut(duration, breaks) -breaks = seq(0, 100, by=10) -breaks -cut(intervals, breaks) -intervals.cut = cut(intervals, breaks) -intervals.cut = cut(intervals, breaks, right=FALSE) -intervals.cut -intervals.freq = table(intervals.cut) -cumfreq0 = c(0, cumsum(intervals.freq)) -cumfreq0 -plot(breaks, cumfreq0) -lines(breaks, cumfreq0) -intervals -min(intervals) -max(intervals) -breaks = seq(40.0, 100.0, by=5.0) -intervals.cut = cut(intervals, breaks, right=FALSE) -intervals.cut -floor? -help(floor) -intervals.freq = table(intervals.cut) -intervals.freq -cumfreq0 = c(0, cumsum(intervals.freq)) -cumfreq0 -plot(breaks, cumfreq0) -lines(breaks, cumfreq0) -plot(breaks, cumfreq0, main="Old Faithful Intervals", xlab="Interval minutes", ylab="Cumulative Intervals") -lines(breaks, cumfreq0) -q() -duration = faithful$eruptions -breaks = seq(1.5, 5.5, by=0.5) -duration.cut = cut(duration, breaks, right=FALSE) -duration.freq = table(duration.cut) -duration.cumfreq = cumsum(duration.freq) -duration.cumrelfreq = duration.cumfreq / nrow(faithful) -duration.cumrelfreq -old = options(digits=2) -duration.cumrelfreq -options(old) -duration.cumrelfreq -cbind(duration.cumfreq, duration.cumrelfreq) -interval = faithful$waiting -min(interval) -max(interval) -ceiling(max(interval)) -help(ceiling) -interval * 0.10 -max(interval) * 0.1) -ceiling(max(interval) * 0.1) -interval_breaks = seq(floor(min(interval) * 0.1) * 10.0, ceiling(max(interval) * 0.1) * 10.0, right=FALSE) -interval_breaks -interval_breaks = seq(floor(min(interval) * 0.1) * 10.0, ceiling(max(interval) * 0.1) * 10.0, by=nrow(interval) / 10.0, right=FALSE) -interval_breaks = seq(floor(min(interval) * 0.1) * 10.0, ceiling(max(interval) * 0.1) * 10.0, by=(nrow(faithful) / 10.0), right=FALSE) -interval_breaks -interval_breaks = seq(floor(min(interval) * 0.1) * 10.0, ceiling(max(interval) * 0.1) * 10.0, by=(nrow(faithful) / 5.0), right=FALSE) -interval_breaks -interval_breaks = seq(floor(min(interval) * 0.1) * 10.0, ceiling(max(interval) * 0.1) * 10.0, by=(nrow(faithful) / 20.0), right=FALSE) -interval_breaks -interval_breaks = seq(floor(min(interval) * 0.1) * 10.0, ceiling(max(interval) * 0.1) * 10.0, by=(nrow(faithful) / 30.0), right=FALSE) -interval_breaks -interval_breaks = seq(floor(min(interval) * 0.1) * 10.0, ceiling(max(interval) * 0.1) * 10.0, by=5.0 right=FALSE) -interval_breaks = seq(floor(min(interval) * 0.1) * 10.0, ceiling(max(interval) * 0.1) * 10.0, by=5.0, right=FALSE) -interval_breaks -length(interval_breaks) -type(interval_breaks) -typeof(interval_breaks) -interval -interval.freq -interval.cut = cut(interval, interval_breaks, right=FALSE) -interval.cut -interval.freq = table(interval.cut) -interval.cumfreq = cumsum(interval.freq) -interval.cumfreq -interval.cumrelfreq = interval.cumfreq / nrow(faithful) -interval.cumrelfreq -cbind(interval.cumfreq, interval.cumrelfreq) -q() -c(duration.freq) -duration.freq) -duration.freq -c(0, duration.freq) -cumfreq0 -cumfreq0 = c(0, cumsum(duration.freq)) -cumfreq0 -cumrelfreq0 = cumfreq0 / nrow(faithful) -cumrelfreq0 -breaks -plot(breaks, cumrelfreq0, main="Old Faithful Eruptions", xlab="Duration minutes", ylab="Cumulative Eruptions Proportion") -lines(breaks, cumrelfreq0) -library(actuar) -help("library") -library(actuar) -help(ogive) -Fn = ogive(breaks, duration.freq) -plot(Fn, main="Old Faithful Eruptions", xlab="Duration minutes", ylab="Cumulative Relative Frequency") -library(PBSModelling) -library(PBSModeling) -library(PBSmodelling) -plotCsum(duration) -intervals -intervals.cut -interval_breaks -interval -intervals -interval.cut -interval.freq -intervalFn = ogive(breaks, interval.freq) -intervalFn = ogive(interval_breaks, interval.freq) -plot(intervalFn, main="Old Faithful Eruptions", xlab="Intervals in minutes", ylab="Cumulative Relative Frequency") -plotCsum(interval) -q() -duration -stem(duration) -interval -stem(interval) -interval -help(stem) -q() -waiting = faithful$waiting -head(cbind(duration, waiting)) -plot(duration, waiting, xlab="Eruption duration", ylab="Time waited") -par() -plot(1:10, 1:10, type="n") -help("font") -??font -# the above was a brief excursion into font settings and such -abline(lm(waiting - duration)) -plot(duration, waiting, xlab="Eruption duration", ylab="Time waited") -abline(lm(waiting - duration)) -abline(lm(waiting ~ duration)) -q() -mean(duration) -mean(interval) -??points -median(duration) -median(interval) -quantile(duration) -quantile(interval) -quantile(duration, c(.32, .57, .98)) -quantile(interval, c(.17, .43, .67, .85)) -q() -q() -max(duration) -min(duration) -max(interval) - min(interval) -IQR(duration) -IQR(interval) -boxplot(duration, horizontal=TRUE) -boxplot(interval, horizontal=TRUE) -q -q() -var(duration) -var(interval) -max(interval) - min(interval) -sd(duration) -sd(interval) -waiting -interval == waiting -cov(duration, waiting) -q() diff --git a/r-practice/introduction/.RData b/r-practice/introduction/.RData deleted file mode 100644 index 7ffebb1..0000000 Binary files a/r-practice/introduction/.RData and /dev/null differ diff --git a/r-practice/introduction/.Rhistory b/r-practice/introduction/.Rhistory deleted file mode 100644 index 5771aeb..0000000 --- a/r-practice/introduction/.Rhistory +++ /dev/null @@ -1,146 +0,0 @@ -c(2, 3, 5) -length(c("aa", "bb", "cc", "dd", "ee")) -n = c(2, 3, 5) -s = c("aa", "bb", "cc", "dd", "ee") -c(n, s) -a = c(1, 3, 5, 7) -b = c(1, 2, 4, 8) -5 * a -a + b -a - b -a * b -u = c(10, 20, 30) -v = c(1, 2, 3, 4, 5, 6, 7, 8, 9) -u + v -a[0] -a[1] -b -b[0] -b[1] -b -b[-2] -b[20] -b[c(2, 3)] -a -a[c(1, 4)] -a -a[1:4] -a[1:3] -a[c(FALSE, TRUE, FALSE, TRUE)] -v = c("Mary", "Sue") -names(v) -names(v) = c("First", "Last") -names(v) -v["First"] -A = matrix( - c(2, 4, 3, 1, 5, 7), - nrow=2, - ncol=3, - byrow=TRUE) -A -A[1, 3] -A[2,] -A[, c(1, 3)] -dimnames(A) = list( - c("row1", "row2"), - c("col1", "col2", "col3")) -A -A["row2", "col3"] -B = matrix( - c(2, 4, 3, 1, 5, 7), - nrow=3, - ncol=2) -B -t(B) -C = matrix( - c(7, 4, 2), - nrow=3, - ncol=1) -C -cbind(B, C) -D = matrix( - c(6, 2), - nrow=1, - ncol=2) -D -B -BD = rbind(B, D) -BD -c(B) -n = c(2, 3, 5) -s = c("aa", "bb", "dd", "ee") -b = c(TRUE, FALSE, TRUE, FALSE, FALSE) -x = list(n, s, b, 3) -x -x[2] -x[1] -x[2] -x[[2]] -x[[2]][1] = "DORP" -x[[2]] -s -v = list(bob=list("Bob", "Johnson", c(2, 3, 5)), john=list("John", "Smythe", c(1, 4, 6))) -v -v["bob"] -v[["bob"]] -v[["bob"]][[1]] -v[["bob"]][[1]] = "Robert" -v["bob"] -v$bob -v$john -v$john[1] -v$john[[1]] -v$john[[1]] = -"Johnny" -v$john -attach(v) -bob -detach(v) -bob -mtcars -n = c(2, 3, 5) -s = c("aa", "bb", "cc") -b = c(TRUE, FALSE, TRUE) -df = data.frame(n, s, b) -mtcars["Mazda RX4", "mpg"] -nrow(mtcars) -ncol(mtcars) -ncol(s) -s -B -nrow(B) -ncol(B) -head(mtcars) -q() -s -q() -mtcars[[[9]] -mtcars[[9]] -mtcars[["am]] -mtcars[["am"]] -mtcars$am -mtcars[1] -head(mtcars[1]) -mtcars["mpg"] -mtcars[c("mpg", "hp")] -mtcars[c("mpg", "hp")][1] -mtcars[c("mpg", "hp")][[1]] -mtcars[24,] -mtcars["Camaro Z28",] -mtcars[c("Datsun 710", "Camaro Z28")] -mtcars[c("Datsun 710", "Camaro Z28",)] -mtcars[c("Datsun 710", "Camaro Z28"),] -L = mtcars$am == 0 -L -mtcars[L,] -mtcars[L,] -mtcars[L,]$mpg -library(gdata) -library(foreign) -help(read.mtp) -mydata = read.table("mydata.txt") -mydata -mydata = read.csv("mydata.csv") -mydata -getwd() -q() diff --git a/r-practice/introduction/mydata.csv b/r-practice/introduction/mydata.csv deleted file mode 100644 index 05ab2ef..0000000 --- a/r-practice/introduction/mydata.csv +++ /dev/null @@ -1,4 +0,0 @@ -Col1,Col2,Col3 -100,a1,b1 -200,a2,b2 -300,a3,b3 diff --git a/r-practice/introduction/mydata.txt b/r-practice/introduction/mydata.txt deleted file mode 100644 index 018793a..0000000 --- a/r-practice/introduction/mydata.txt +++ /dev/null @@ -1,4 +0,0 @@ -100 a1 b1 -200 a2 b2 -300 a3 b3 -400 a4 b4 diff --git a/r-practice/just-testing.R b/r-practice/just-testing.R deleted file mode 100644 index c138c7c..0000000 --- a/r-practice/just-testing.R +++ /dev/null @@ -1,12 +0,0 @@ -# Yes, this is just a test to make sure I'm remotely -# capable of writing and running an R file. - - -print("dogs rule cats drool") - -x = 10.5 -y = as.integer(4) - -print(x + y) - -# vim:filetype=r