lpg-0.4.examples/004077500005330001752000000000000663513056200143235ustar00greghlinux00002640000002lpg-0.4.examples/splay.c010060000005330001752000000031740563436706300156150ustar00greghlinux00002640000002/* * AUTHOR: Sven Goldt (goldt@math.tu-berlin.de) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * */ #include #include #include #include #include #include #include #include #include extern float name_to_val(char *tune); main(int argc, char **argv) { int fd=1,tone,duration; float frequency; char sounddata[20]; if (argc>1) { fprintf(stderr,"I need sounddatas from stdin !\n"); exit(-1); } if (strncmp(getenv("TERM"), "xterm", 5) == 0) { fd = open("/dev/console", O_WRONLY); if (fd < 0) fd = 1; /* stdout */ } while (fgets(sounddata,20,stdin)!=NULL) { if (isalpha(*sounddata)) { strtok(sounddata,"\t, "); /* delimiters for frequency and length */ frequency=name_to_val(sounddata); sscanf(strtok(NULL,"\r"),"%d",&duration); } else sscanf(sounddata,"%f%*c%d",&frequency,&duration); if (frequency!=0.0) tone=1190000/frequency;/*calculate value for pc speaker*/ else tone=0; ioctl(fd,KIOCSOUND,tone); usleep(duration*1000); /* duration in ms */ } ioctl(fd,KIOCSOUND,0); /* sound off */ if (fd>2) close(fd); /* console */ exit(0); } lpg-0.4.examples/translate.c010060000005330001752000000045260563436702000164550ustar00greghlinux00002640000002/* * AUTHOR: Sven Goldt (goldt@math.tu-berlin.de) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * */ #include static struct s_notes { float frequency; char name[4]; } notes[] = { 16.4 , "c-0", 17.3 , "c#0", 18.4 , "d-0", 19.4 , "d#0", 20.6 , "e-0", 21.8 , "f-0", 23.1 , "f#0", 24.5 , "g-0", 26.0 , "g#0", 27.5 , "a-0", 29.1 , "a#0", 30.9 , "h-0", 32.7 , "c-1", 34.6 , "c#1", 36.7 , "d-1", 38.9 , "d#1", 41.2 , "e-1", 43.7 , "f-1", 46.2 , "f#1", 49.0 , "g-1", 51.9 , "g#1", 55.0 , "a-1", 58.3 , "a#1", 61.7 , "h-1", 65.4 , "c-2", 69.3 , "c#2", 73.4 , "d-2", 77.8 , "d#2", 82.4 , "e-2", 87.3 , "f-2", 92.5 , "f#2", 98.0 , "g-2", 103.8, "g#2", 110.0, "a-2", 116.5, "a#2", 123.5, "h-2", 130.8, "c-3", 138.6, "c#3", 146.8, "d-3", 155.6, "d#3", 164.8, "e-3", 174.6, "f-3", 185.0, "f#3", 196.0, "g-3", 207.7, "g#3", 220.0, "a-3", 233.1, "a#3", 246.9, "h-3", 261.6, "c-4", 277.2, "c#4", 293.7, "d-4", 311.1, "d#4", 329.6, "e-4", 349.2, "f-4", 370.0, "f#4", 392.0, "g-4", 415.3, "g#4", 440.0, "a-4", 466.2, "a#4", 493.9, "h-4", 523.3, "c-5", 554.4, "c#5", 587.3, "d-5", 622.3, "d#5", 659.3, "e-5", 698.5, "f-5", 740.0, "f#5", 784.0, "g-5", 830.6, "g#5", 880.0, "a-5", 932.3, "a#5", 987.8, "h-5", 1046.5, "c-6", 1108.7, "c#6", 1174.7, "d-6", 1244.5, "d#6", 1318.5, "e-6", 1396.6, "f-6", 1480.0, "f#6", 1568.0, "g-6", 1661.2, "g#6", 1760.0, "a-6", 1864.7, "a#6", 1975.5, "h-6", 2093.0, "c-7", 2217.5, "c#7", 2349.3, "d-7", 2489.0, "d#7", 2637.0, "e-7", 2793.8, "f-7", 2960.0, "f#7", 3136.0, "g-7", 3322.4, "g#7", 3520.0, "a-7", 3729.3, "a#7", 0.0 , "0", }; float name_to_val(char *tune) { struct s_notes *ptr; for (ptr=notes; ptr->frequency !=0; ptr++) if (strncmp(tune,ptr->name,3) == 0) return(ptr->frequency); return(0.0); } char *val_to_name(float frequency) { struct s_notes *ptr; for (ptr=notes; ptr->frequency !=0; ptr++) if (ptr->frequency == frequency) return(ptr->name); return(NULL); } lpg-0.4.examples/splay.1010060000005330001752000000013130564431555100155200ustar00greghlinux00002640000002.TH SPLAY 1 "September 1994" "splay Version 1.0" .SH NAME splay \- play .sng files to pc speaker .SH SYNOPSIS .B splay awaits input from stdin .SH DESCRIPTION .B splay reads music datas from stdin. It uses it's own sound data format which usually are saved in a .sng file. A line in a .sng file contains 2 values - the frequency and the duration of a tone. The frequency can be a numeric float value measured in Hertz or a music note name like c-1 or c#1. The duration is an integer value for the tone length in milliseconds. A quarter music note is usually a length of 250 ms. .SH EXAMPLE splay < music.sng .SH AUTHOR splay has been written by Sven Goldt .br .SH "SEE ALSO" .BR vplay (1) lpg-0.4.examples/Makefile010060000005330001752000000021010573754145000157440ustar00greghlinux00002640000002CC=gcc LINK = $(CC) CFLAGS = -O2 -pipe -m386 #-Wall LDFLAGS = -s SRC = splay.c translate.c checklp.c miniterm.c type.c input.c calc.c \ screen.c USEFUL_TARGETS = splay checklp miniterm TARGETS = $(USEFUL_TARGETS) type input screen calc all: $(TARGETS) @echo make done. splay: splay.o translate.o $(LINK) splay.o translate.o $(LDFLAGS) -o $@ input: input.o $(LINK) input.o -lncurses $(LDFLAGS) -o $@ type: type.o $(LINK) type.o -lncurses $(LDFLAGS) -o $@ screen: screen.o $(LINK) screen.o -lncurses $(LDFLAGS) -o $@ calc: calc.o $(LINK) calc.o -lncurses $(LDFLAGS) -o $@ install: @echo usage: make install.all or install.bin or install.man install.all: $(USEFUL_TARGETS) install.man install.bin install.bin: $(USEFUL_TARGETS) install -m 555 $(USEFUL_TARGETS) /usr/local/bin install.man: install -m 444 *.1 /usr/local/man/man1 install -m 444 *.8 /usr/man/man8 clean: rm -f *.o core $(TARGETS) depend: makedepend $(SRC) ci: ci -m"I hate log messages!" -t-"I hate description prompts!" -l $(SRC) Makefile co: co $(SRC) Makefile .c.o: $(CC) $(CFLAGS) -c $< lpg-0.4.examples/all.sng010060000005330001752000000001640563540223000155610ustar00greghlinux00002640000002c-5 500 0 50 d-5 180 c-5 180 d-5 180 c-5 500 0 50 c-5 500 e-5 180 c-5 180 d-5 180 c-5 450 0 50 c-5 250 0 50 h-4 400 lpg-0.4.examples/music.sng010060000005330001752000000001510563423022600161300ustar00greghlinux00002640000002c-4 250 e-4 250 g-4 400 e-4 100 g-4 250 a-4 250 g-4 250 0 250 e-4 250 g-4 250 a-4 250 g-4 250 lpg-0.4.examples/selection-1.8.tar.gz010060000005330001752000000615710563621526300177420ustar00greghlinux00002640000002Hx.\[s9v֦N=ڙ*KE48dJ5cI.IlRc$av7:}LW~t~BsPN2$b-6 wUBZU>BA=;_ ;zw5v?_qʿp^w78ԅ;HJKv;ԄeD/ĔI(fJdD+a&bE);BБ.bb2PY܍\K!KeM"^ :+J~H̫YbS%=0%2C N վ牮 PXK^\( Mw/TBL?i҅ "JL0*f;AG& @ u-{7:L]-LJv\,lj*^Ų'B.),Q*’b%) fԲ=r1o03&@,Q,ԉdPY$4$31MCRb$"Ql ;X'2[vf;R`|ϻʐT䜦 1(AORDKH$c>Otk+/\ʇr*,rŊu`>H_be7PZ'!ky3=䮋3$\F&ay.* _3i-'S*Zz%[ >2=. vDf'2n!0T/TB7eo{?zk?aiwhj{@D{ǵoڣ<^fmop@ރX ~_\])nov]=[߭{XNWDkL"B'0YX?]LyG\όt\5Ndhu"LFi \"0tI!ǡKS"pPʂ ,"Qv>ǥ)t2k:2)#Gy؞ ue3ca78 x^Y1+3a1?>zF&h# Kr`9<^ZSTmq*Рg(~}) "0O;Ҍq鹸 #u]Зer? c5MIgL+ΉrpU.e2ݱ fe>~cuė[۟\!Gxj2qXʄ*Ou0@ϥB<*`ow%Kƀs?5&]e-tI~NPU>թLfVI&åx,}/҈e!?%&$ziӝ|)хo/9TdD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[.,]zJ]Ɋ ^@}kQm!ZTqYBx%/^Se:m0) s`<;Jyp:n(ږ`G%3>0 Ve,/ܝJH΄f<غ YQ sqwRM 6hyu1BIֆ* u;ЃG {^‚+\Dn\:J ȇk(Ϭ 6|0~Xe͜ RN~f4 ߟ8`BۣtCۚەa>C!0P"a2D"7wnw75Bb9pFϮZF=D~Qb-AQ;eAuoPz 4R-0yԾL2Y­lpg-0.4.examples/type.c010060000005330001752000000207530573235556000154460ustar00greghlinux00002640000002/* * TYPE.C - A demonstration program for ncurses. * This program is originally distributed as a part of * the * * AUTHOR: Sven van der Meer (vdmeer@cs.tu-berlin.de) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License,or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include "type.h" /* My background window has 22 rows and 70 columns. These * two defines are logical coordinates to open the window * in the middle of the screen, whatever dimension it has. * TYPE_ROW is the beginning row for my program and TYPE_COL * the beginning column. Every call to newwin(...) will check * these two defines. */ #define TYPE_ROW (int) ((LINES-22)/2) #define TYPE_COL (int) ((COLS-70)/2) /* * Global variables. I need three windows (one for the red box, * one for the frame and one for the real output). Beg is for * the output as offset in s[]. Scroll is an enum for calls to * scroll_s (I hate to use integers for this). * s[] is defined in type.h as: * char *s[] = { }; */ WINDOW *screen_win; WINDOW *type_win; WINDOW *print_win; int beg=0; int max_s=340; enum scroll{UP,DOWN}; /* * Local function prototypes. * init_type does the ncurses initializing * end_type does the exit for type * vdmerase will erase a window with blanks (I had problems * with the ncurses erase functions, so I wrote my * function). * scroll_s will do the scrolling (UP or DOWN). * clear_line will send space characters from the current * cursor position up to * the length from int. * winsizech() is a signalhandler for SIGWINCH. this signal * will be caught when the screen size has changed * (resized xterm e.g.). */ void init_type(); void end_type(); void vdmerase(WINDOW *); void scroll_s(int); void clear_line(int, WINDOW *); void winsizech(); /* * The main function. */ void main () { bool okloop=TRUE; /* ncurses initializing */ init_type(); /* set signal handler for SIGWINCH */ signal(SIGWINCH,winsizech); /* ok, the screen has a white window with a box and a red * border around it. * Our main loop. Wait for pressed keys. When the user pressed * 'q' or 'Q' then exit the program. On cursor down or 'd' or 'D' * scroll the text in the window one line down, on cursor up or * 'u' or 'U' one line up. On every other key do nothing. */ while(okloop){ switch(getch()){ case KEY_UP: case 'u': case 'U': scroll_s(UP); break; case KEY_DOWN: case 'd': case 'D': scroll_s(DOWN); break; case 'q': case 'Q': okloop=FALSE; break; default : break; } } /* clean uop end exit */ end_type(); exit(0); } /* * init_type initialize the ncurses data structures, create the * needed windows, print them on screen and set some * usefull options. * */ void init_type() { int i; /* don't forget this when using ncurses!!! */ if(!(stdscr=initscr())){ fprintf(stderr,"type: initscr() failed\n\n"); exit (1); } /* check screen size. we need 22 lines and 70 columns */ if ((LINES<22)||(COLS<70)){ fprintf(stderr,"type: screen to small\n\n"); endwin(); exit (1); } /* now we open our three windows */ if (!(screen_win=newwin(22,70,TYPE_ROW,TYPE_COL))){ fprintf(stderr,"type: can't open screen_win\n\n"); endwin(); exit (1); } if (!(type_win=newwin(20,68,TYPE_ROW+1,TYPE_COL+1))){ fprintf(stderr,"type: can't open type_win\n\n"); endwin(); exit (1); } if (!(print_win=newwin(18,66,TYPE_ROW+2,TYPE_COL+2))){ fprintf(stderr,"type: can't open type_win\n\n"); endwin(); exit (1); } /* ok windows are opened, check for color */ start_color(); if (has_colors()){ /* fine we have colors, define color_pairs for foreground * and background colors */ init_pair(1,COLOR_BLUE,COLOR_WHITE); init_pair(2,COLOR_WHITE,COLOR_RED); init_pair(3,COLOR_BLACK,COLOR_WHITE); /* now use the defined color_pairs for the windows */ wattrset(screen_win,COLOR_PAIR(2)); wattrset(type_win,COLOR_PAIR(1)); wattrset(print_win,COLOR_PAIR(3)); } else{ /* ohh, no color (maybe a vt100 or xterm). ok we use b&w * attributes instead */ wattrset(screen_win,A_REVERSE); wattrset(type_win,A_BOLD); wattrset(print_win,A_NORMAL); } /* now clear the windows to get the attributes visible * (in memory not on the screen). */ vdmerase(screen_win); vdmerase(type_win); vdmerase(print_win); /* wborder with spaces will only paint the border red */ wborder(screen_win,' ',' ',' ',' ',' ',' ',' ',' '); /* and now the real box characters */ box(type_win,0,0); /* some additional information. * ACS_* character and german 'umlaute' are not printed * correctly in ncurses 1.8.5 and the terminfo from * slackware 2.0, so I don't use them */ mvwaddstr(type_win,0,29,"[ type.c ]"); mvwaddstr(screen_win,21,1,"[Q,q]-Quit "); waddch(screen_win,ACS_DARROW); waddstr(screen_win,"[D,d]-Scroll down one line "); waddch(screen_win,ACS_UARROW); waddstr(screen_win,"[U,u]-Scroll up one line"); /* it's time to print the strings on the screen */ for(i=beg;i<19;i++) mvwaddnstr(print_win,i,0,s[i],66); /* Now the terminal options. * noecho the user typed characters, don't wait for input, * make cursor invisible, don't wait for carriage return * while waiting for input and enable the keypad */ noecho(); nodelay(stdscr,FALSE); cbreak(); curs_set(FALSE); keypad(stdscr,TRUE); /* all window manipulations are done in the memory * now we are going to get in on the physical screen. * wnoutrefresh does everything in the memory, too, and * doupdate will paint our screen!!! */ wnoutrefresh(screen_win); wnoutrefresh(type_win); wnoutrefresh(print_win); doupdate(); } /* The user wants to terminate the program, ok clean up. * Delete all opened windows and make the cursor visible. * At least call endwin. */ void end_type() { delwin(screen_win); delwin(type_win); delwin(print_win); curs_set(TRUE); endwin(); } /* * With 'erase' and 'werase' from ncurses I don't get white * spaces on black background (any idea why?), so I use * my own erase function. * This goes deep in the structure WINDOW, so I don't recommend * to use this function!!! */ void vdmerase (WINDOW *win) { int y,x; for (y=0;y<=win->_maxy;y++) for (x=0;x<=win->_maxx;x++) (chtype *)win->_line[y][x]=' '|win->_attrs; win->_curx = win->_cury = 0; touchwin(win); return; } /* * This function will scroll the lines on the screen, using * ncurses (and the optimization in ncurses). * UP and DOWN are enum's, beg is an offset for printing * s[]. * If we scroll down (wscrl(win,positive integer) the last * line on screen is empty and we print the new one to * the screen (the same on scrolling up with the first line). * Clear_line prints spaces from the current cursor position * up to the end of the line. */ void scroll_s(int scroll) { WINDOW *win=print_win; if((scroll==DOWN)&&(beg<=(max_s-18))){ beg++; scrollok(win, TRUE); wscrl(win, +1); scrollok(win, FALSE); mvwaddnstr(win,17,0,s[beg+17],66); clear_line(66,win); } else if((scroll==UP)&&(beg>0)){ beg--; scrollok(win, TRUE); wscrl(win, -1); scrollok(win, FALSE); mvwaddnstr(win,0,0,s[beg],66); clear_line(66,win); } wrefresh(win); return; } /* * Clear_line prints spaces from the current cursor position * up to length */ void clear_line(int length,WINDOW *win) { int i,y_start,x_start; getyx(win,y_start,x_start); for(i=x_start+1; i<=length;i++) waddch(win,' '); return; } /* * Signal handler for SIGWINCH. When this signal is received, * we clean up all windows (delwin), then call endwin and * reinitialize the whole program. it's not fine but it works. * For 'real' programs we need some better functions I think. * */ void winsizech() { end_type(); init_type(); signal(SIGWINCH,winsizech); } lpg-0.4.examples/type.h010060000005330001752000000246760571422711000154500ustar00greghlinux00002640000002/* * TYPE.H - Header for TYPE.C - A demonstration program for ncurses. * This program is originally distributed as a part of the * Linux Programmers Guide * * AUTHOR: Sven van der Meer * Copyright (c) 1994 Sven van der Meer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Problems or comments to vdmeer@cs.tu-berlin.de * */ char *s[]= { "", "TYPE.C - A demonstration program for ncurses.", " This program is originally distributed as a part of ", " the ", "", "AUTHOR: Sven van der Meer (vdmeer@cs.tu-berlin.de)", "", "This program is free software; you can redistribute it and/or", "modify it under the terms of the GNU General Public License as", "published by the Free Software Foundation; either version 2 of", "the License,or (at your option) any later version.", "", "This program is distributed in the hope that it will be useful,", "but WITHOUT ANY WARRANTY; without even the implied warranty of", "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the", "GNU General Public License for more details.", "", "You should have received a copy of the GNU General Public License", "along with this program; if not, write to the Free Software", "Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.", "", "", "", "#include ", "#include ", "#include \"type.h\"", "", "", "/* My background window has 22 rows and 70 columns. These ", " * two defines are logical coordinates to open the window", " * in the middle of the screen, whatever dimension it has.", " * TYPE_ROW is the beginning row for my program and TYPE_COL ", " * the beginning column. Every call to newwin(...) will check", " * these two defines.", " */", "#define TYPE_ROW (int) ((LINES-22)/2)", "#define TYPE_COL (int) ((COLS-70)/2)", "", "", "/*", " * Global variables. I need three windows (one for the red box,", " * one for the frame and one for the real output). Beg is for", " * the output as offset in s[]. Scroll is an enum for calls to", " * scroll_s (I hate to use integers for this).", " * s[] is defined in type.h as:", " * char *s[] = { };", " */", "WINDOW *screen_win;", "WINDOW *type_win;", "WINDOW *print_win;", "int beg=0;", "int max_s=294;", "enum scroll{UP,DOWN};", "", "", "/*", " * Local function prototypes.", " * init_type does the ncurses initializing", " * end_type does the exit for type", " * vdmerase will erase a window with blanks (I had problems", " * with the ncurses erase functions, so I wrote my", " * function).", " * scroll_s will do the scrolling (UP or DOWN).", " * clear_line will send space characters from the current ", " * cursor position up to", " * the length from int.", " * winsizech() is a signalhandler for SIGWINCH. this signal", " * will be caught when the screen size has changed", " * (resized xterm e.g.).", " */", "void init_type();", "void end_type();", "void vdmerase(WINDOW *);", "void scroll_s(int);", "void clear_line(int, WINDOW *);", "void winsizech();", "", "", "", "/*", " * The main function.", " */", "void main ()", "{", "bool okloop=TRUE;", "", " /* ncurses initializing */", " init_type();", "", " /* set signal handler for SIGWINCH */", " signal(SIGWINCH,winsizech);", "", "/* ok, the screen has a white window with a box and a red", " * border around it.", " * Our main loop. Wait for pressed keys. When the user pressed", " * 'q' or 'Q' then exit the program. On cursor down or 'd' or 'D'", " * scroll the text in the window one line down, on cursor up or", " * 'u' or 'U' one line up. On every other key do nothing.", " */", " while(okloop){", " switch(getch()){", " case KEY_UP:", " case 'u':", " case 'U': scroll_s(UP);", " break;", " case KEY_DOWN:", " case 'd':", " case 'D': scroll_s(DOWN);", " break;", " case 'q':", " case 'Q': okloop=FALSE;", " break;", " default : break;", " }", " }", " /* clean uop end exit */", " end_type();", " exit(0);", "}", "", "", "", "", "/*", " * init_type initialize the ncurses data structures, create the", " * needed windows, print them on screen and set some", " * usefull options.", " *", " */", "void init_type()", "{", "int i;", "", "/* don't forget this when using ncurses!!! */", " if(!(stdscr=initscr())){", " fprintf(stderr,\"type: initscr() failed\n\n\");", " exit (1);", " }", "", "/* check screen size. we need 22 lines and 70 columns */", " if ((LINES<22)||(COLS<70)){", " fprintf(stderr,\"type: screen to small\n\n\");", " endwin(); exit (1);", " }", "", "/* now we open our three windows */", " if (!(screen_win=newwin(22,70,TYPE_ROW,TYPE_COL))){", " fprintf(stderr,\"type: can't open screen_win\n\n\");", " endwin(); exit (1);", " }", "", " if (!(type_win=newwin(20,68,TYPE_ROW+1,TYPE_COL+1))){", " fprintf(stderr,\"type: can't open type_win\n\n\");", " endwin(); exit (1);", " }", "", " if (!(print_win=newwin(18,66,TYPE_ROW+2,TYPE_COL+2))){", " fprintf(stderr,\"type: can't open type_win\n\n\");", " endwin(); exit (1);", " }", "", "/* ok windows are opened, check for color */", " start_color();", " if (has_colors()){", " /* fine we have colors, define color_pairs for foreground", " * and background colors", " */", " init_pair(1,COLOR_BLUE,COLOR_WHITE);", " init_pair(2,COLOR_WHITE,COLOR_RED);", " init_pair(3,COLOR_BLACK,COLOR_WHITE);", " /* now use the defined color_pairs for the windows */", " wattrset(screen_win,COLOR_PAIR(2));", " wattrset(type_win,COLOR_PAIR(1));", " wattrset(print_win,COLOR_PAIR(3));", " }", " else{", " /* ohh, no color (maybe a vt100 or xterm). ok we use b&w", " * attributes instead", " */", " wattrset(screen_win,A_REVERSE);", " wattrset(type_win,A_BOLD);", " wattrset(print_win,A_NORMAL);", " }", "", "/* now clear the windows to get the attributes visible", " * (in memory not on the screen).", " */", " vdmerase(screen_win);", " vdmerase(type_win);", " vdmerase(print_win);", "", "/* wborder with spaces will only paint the border red */", " wborder(screen_win,' ',' ',' ',' ',' ',' ',' ',' ');", "", "/* and now the real box characters */", " box(type_win,0,0);", "", "/* some additional information.", " * ACS_* character and german 'umlaute' are not printed", " * correctly in ncurses 1.8.5 and the terminfo from", " * slackware 2.0, so I don't use them", " */", " mvwaddstr(type_win,0,29,\"[ type.c ]\");", " mvwaddstr(screen_win,21,1,\"[Q,q]-Quit \");", " waddch(screen_win,ACS_DARROW);", " waddstr(screen_win,\"[D,d]-Scroll down one line \");", " waddch(screen_win,ACS_UARROW);", " waddstr(screen_win,\"[U,u]-Scroll up one line\");", "", "", "/* it's time to print the strings on the screen */", " for(i=beg;i<19;i++)", " mvwaddnstr(print_win,i,0,s[i],66);", "", "", "/* Now the terminal options.", " * noecho the user typed characters, don't wait for input,", " * make cursor invisible, don't wait for carriage return", " * while waiting for input and enable the keypad", " */", " noecho();", " nodelay(stdscr,FALSE);", " cbreak();", " curs_set(FALSE);", " keypad(stdscr,TRUE);", "", "", "/* all window manipulations are done in the memory", " * now we are going to get in on the physical screen.", " * wnoutrefresh does everything in the memory, too, and", " * doupdate will paint our screen!!!", " */", " wnoutrefresh(screen_win);", " wnoutrefresh(type_win);", " wnoutrefresh(print_win);", " doupdate();", "}", "", "", "", "/* The user wants to terminate the program, ok clean up.", " * Delete all opened windows and make the cursor visible.", " * At least call endwin.", " */", "void end_type()", "{", " delwin(screen_win);", " delwin(type_win);", " delwin(print_win);", " curs_set(TRUE);", " endwin();", "}", "", "", "", "/*", " * With 'erase' and 'werase' from ncurses I don't get white", " * spaces on black background (any idea why?), so I use ", " * my own erase function.", " * This goes deep in the structure WINDOW, so I don't recommend", " * to use this function!!!", " */", "void vdmerase (WINDOW *win)", "{", "int y,x;", "", " for (y=0;y<=win->_maxy;y++)", " for (x=0;x<=win->_maxx;x++)", " (chtype *)win->_line[y][x]=' '|win->_attrs;", " win->_curx = win->_cury = 0;", " touchwin(win);", "return;", "}", "", "", "", "/*", " * This function will scroll the lines on the screen, using", " * ncurses (and the optimization in ncurses).", " * UP and DOWN are enum's, beg is an offset for printing", " * s[].", " * If we scroll down (wscrl(win,positive integer) the last", " * line on screen is empty and we print the new one to", " * the screen (the same on scrolling up with the first line).", " * Clear_line prints spaces from the current cursor position", " * up to the end of the line.", " */", "void scroll_s(int scroll)", "{", "WINDOW *win=print_win;", "", " if((scroll==DOWN)&&(beg<=(max_s-18))){", " beg++;", " scrollok(win, TRUE);", " wscrl(win, +1);", " scrollok(win, FALSE);", " mvwaddnstr(win,17,0,s[beg+17],66);", " clear_line(66,win);", " }", " else if((scroll==UP)&&(beg>0)){", " beg--;", " scrollok(win, TRUE);", " wscrl(win, -1);", " scrollok(win, FALSE);", " mvwaddnstr(win,0,0,s[beg],66);", " clear_line(66,win);", " }", " wrefresh(win);", "return;", "}", "", "", "", "/*", " * Clear_line prints spaces from the current cursor position", " * up to length", " */", "void clear_line(int length,WINDOW *win)", "{", "int i,y_start,x_start;", " getyx(win,y_start,x_start);", " for(i=x_start+1; i<=length;i++)", " waddch(win,' ');", "return;", "}", "", "", "", "/*", " * Signal handler for SIGWINCH. When this signal is received,", " * we clean up all windows (delwin), then call endwin and", " * reinitialize the whole program. it's not fine but it works.", " * For 'real' programs we need some better functions I think.", " *", " */", "void winsizech()", "{", " end_type();", " init_type();", " signal(SIGWINCH,winsizech);", "}" }; lpg-0.4.examples/miniterm.c010060000005330001752000000067440571106305400163040ustar00greghlinux00002640000002/* * AUTHOR: Sven Goldt (goldt@math.tu-berlin.de) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * */ /* This is like all programs in the Linux Programmer's Guide meant as a simple practical demonstration. It can be used as a base for a real terminal program. */ #include #include #include #include #include #define BAUDRATE B38400 #define MODEMDEVICE "/dev/modem" #define ENDMINITERM 2 /* ctrl-b to quit miniterm */ #define _POSIX_SOURCE 1 /* POSIX compliant source */ #define FALSE 0 #define TRUE 1 volatile int STOP=FALSE; void child_handler(int s) { STOP=TRUE; } main() { int fd,c; struct termios oldtio,newtio,oldstdtio,newstdtio; struct sigaction sa; /* Open modem device for reading and writing and not as controlling tty because we don't want to get killed if linenoise sends CTRL-C. */ fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY); if (fd <0) {perror(MODEMDEVICE); exit(-1); } tcgetattr(fd,&oldtio); /* save current modem settings */ /* Set bps rate and hardware flow control and 8n1 (8bit,no parity,1 stopbit). Also don't hangup automatically and ignore modem status. Finally enable receiving characters. */ newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD; /* Ignore bytes with parity errors and make terminal raw and dumb. */ newtio.c_iflag = IGNPAR; /* Raw output. */ newtio.c_oflag = 0; /* Don't echo characters because if you connect to a host it or your modem will echo characters for you. Don't generate signals. */ newtio.c_lflag = 0; /* blocking read until 1 char arrives */ newtio.c_cc[VMIN]=1; newtio.c_cc[VTIME]=0; /* now clean the modem line and activate the settings for modem */ tcflush(fd, TCIFLUSH); tcsetattr(fd,TCSANOW,&newtio); /* Strange, but if you uncomment this command miniterm will not work even if you stop canonical mode for stdout. This is a linux bug. */ tcsetattr(1,TCSANOW,&newtio); /* stdout settings like modem settings */ /* next stop echo and buffering for stdin */ tcgetattr(0,&oldstdtio); tcgetattr(0,&newstdtio); /* get working stdtio */ newstdtio.c_lflag &= ~(ICANON | ECHO); tcsetattr(0,TCSANOW,&newstdtio); /* terminal settings done, now handle in/ouput */ switch (fork()) { case 0: /* child */ /* user input */ close(1); /* stdout not needed */ for (c=getchar(); c!= ENDMINITERM ; c=getchar()) write(fd,&c,1); tcsetattr(fd,TCSANOW,&oldtio); /* restore old modem setings */ tcsetattr(0,TCSANOW,&oldstdtio); /* restore old tty setings */ close(fd); exit(0); /* will send a SIGCHLD to the parent */ break; case -1: perror("fork"); tcsetattr(fd,TCSANOW,&oldtio); close(fd); exit(-1); default: /* parent */ close(0); /* stdin not needed */ sa.sa_handler = child_handler; sa.sa_flags = 0; sigaction(SIGCHLD,&sa,NULL); /* handle dying child */ while (STOP==FALSE) /* modem input handler */ { read(fd,&c,1); /* modem */ write(1,&c,1); /* stdout */ } wait(NULL); /* wait for child to die or it will become a zombie */ break; } } ce */ #define FALSE 0 #defilpg-0.4.examples/checklp.8010060000005330001752000000007350564604777700160350ustar00greghlinux00002640000002.TH CHECKLP 8 "September 1994" "checklp Version 1.1" .SH NAME checklp \- examine printers .SH DESCRIPTION .B checklp tries to obtain basic datas about your printers like IRQ settings and printer status report. Only root can use .B checklp. .SH BUGS .B checklp might fail if you didn't configure the kernel printer driver correct. .SH AUTHOR checklp has been written by Sven Goldt .br .SH "SEE ALSO" .BR tunelp (8) , .BR lptest (1) , .BR lpg-0.4.examples/checklp.c010060000005330001752000000034530570626624700161000ustar00greghlinux00002640000002/* * AUTHOR: Sven Goldt (goldt@math.tu-berlin.de) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * */ /* * * Changes in 1.1: Fixed bit meaning for low active lines ! * */ #include #include /* #include DAMNED ! - Some butthead crippled that file !!! */ #include "oldlp.h" #include #ifndef LP_NO #define LP_NO 3 #endif main() { int i,fd,irq; unsigned char status=0; char printer[10]; for (i=0;i0) printf("irq = %d\n",irq); else printf("polling driver used\n"); printf(" I/O base address is 0x%x for %s\n",LP_B(i),printer); if (ioperm(LP_B(i)+1,1,1)<0) { printf("access to port 0x%x denied\n",LP_B(i)+1); continue; } status=inb(LP_B(i)+1); printf(" printer is%sand%sbusy\n", (status & LP_PSELECD) ? " online " : " offline ", (status & LP_PBUSY) ? " not " : " "); printf(" printer is%swaiting for datas\n",(status & LP_PACK) ? " not " : " "); printf(" paper is%sempty\n",(status & LP_POUTPA) ? " " : " not "); printf(" printer is signalling%serror\n", (status & LP_PERRORP) ? " no " : " an "); } } lpg-0.4.examples/oldlp.h010060000005330001752000000112310565057235000155700ustar00greghlinux00002640000002#ifndef _LINUX_LP_H #define _LINUX_LP_H /* * usr/include/linux/lp.h c.1991-1992 James Wiegand * many modifications copyright (C) 1992 Michael K. Johnson * Interrupt support added 1993 Nigel Gamble */ /* * Per POSIX guidelines, this module reserves the LP and lp prefixes * These are the lp_table[minor].flags flags... */ #define LP_EXIST 0x0001 #define LP_SELEC 0x0002 #define LP_BUSY 0x0004 #define LP_OFFL 0x0008 #define LP_NOPA 0x0010 #define LP_ERR 0x0020 #define LP_ABORT 0x0040 /* timeout for each character. This is relative to bus cycles -- it * is the count in a busy loop. THIS IS THE VALUE TO CHANGE if you * have extremely slow printing, or if the machine seems to slow down * a lot when you print. If you have slow printing, increase this * number and recompile, and if your system gets bogged down, decrease * this number. This can be changed with the tunelp(8) command as well. */ #define LP_INIT_CHAR 1000 /* The parallel port specs apparently say that there needs to be * a .5usec wait before and after the strobe. Since there are wildly * different computers running linux, I can't come up with a perfect * value, but since it worked well on most printers before without, * I'll initialize it to 0. */ #define LP_INIT_WAIT 0 /* This is the amount of time that the driver waits for the printer to * catch up when the printer's buffer appears to be filled. If you * want to tune this and have a fast printer (i.e. HPIIIP), decrease * this number, and if you have a slow printer, increase this number. * This is in hundredths of a second, the default 2 being .05 second. * Or use the tunelp(8) command, which is especially nice if you want * change back and forth between character and graphics printing, which * are wildly different... */ #define LP_INIT_TIME 2 /* IOCTL numbers */ #define LPCHAR 0x0001 /* corresponds to LP_INIT_CHAR */ #define LPTIME 0x0002 /* corresponds to LP_INIT_TIME */ #define LPABORT 0x0004 /* call with TRUE arg to abort on error, FALSE to retry. Default is retry. */ #define LPSETIRQ 0x0005 /* call with new IRQ number, or 0 for polling (no IRQ) */ #define LPGETIRQ 0x0006 /* get the current IRQ number */ #define LPWAIT 0x0008 /* corresponds to LP_INIT_WAIT */ /* timeout for printk'ing a timeout, in jiffies (100ths of a second). This is also used for re-checking error conditions if LP_ABORT is not set. This is the default behavior. */ #define LP_TIMEOUT_INTERRUPT (60 * HZ) #define LP_TIMEOUT_POLLED (10 * HZ) #define LP_B(minor) lp_table[(minor)].base /* IO address */ #define LP_F(minor) lp_table[(minor)].flags /* flags for busy, etc. */ #define LP_S(minor) inb_p(LP_B((minor)) + 1) /* status port */ #define LP_C(minor) (lp_table[(minor)].base + 2) /* control port */ #define LP_CHAR(minor) lp_table[(minor)].chars /* busy timeout */ #define LP_TIME(minor) lp_table[(minor)].time /* wait time */ #define LP_WAIT(minor) lp_table[(minor)].wait /* strobe wait */ #define LP_IRQ(minor) lp_table[(minor)].irq /* interrupt # */ /* 0 means polled */ #define LP_BUFFER_SIZE 256 struct lp_struct { int base; unsigned int irq; int flags; unsigned int chars; unsigned int time; unsigned int wait; struct wait_queue *lp_wait_q; char *lp_buffer; }; /* the BIOS manuals say there can be up to 4 lpt devices * but I have not seen a board where the 4th address is listed * if you have different hardware change the table below * please let me know if you have different equipment * if you have more than 3 printers, remember to increase LP_NO */ struct lp_struct lp_table[] = { { 0x3bc, 0, 0, LP_INIT_CHAR, LP_INIT_TIME, LP_INIT_WAIT, NULL, NULL, }, { 0x378, 0, 0, LP_INIT_CHAR, LP_INIT_TIME, LP_INIT_WAIT, NULL, NULL, }, { 0x278, 0, 0, LP_INIT_CHAR, LP_INIT_TIME, LP_INIT_WAIT, NULL, NULL, }, }; #define LP_NO 3 /* * bit defines for 8255 status port * base + 1 * accessed with LP_S(minor), which gets the byte... */ #define LP_PBUSY 0x80 /* active low */ #define LP_PACK 0x40 /* active low */ #define LP_POUTPA 0x20 #define LP_PSELECD 0x10 #define LP_PERRORP 0x08 /* active low*/ /* * defines for 8255 control port * base + 2 * accessed with LP_C(minor) */ #define LP_PINTEN 0x10 #define LP_PSELECP 0x08 #define LP_PINITP 0x04 /* active low */ #define LP_PAUTOLF 0x02 #define LP_PSTROBE 0x01 /* * the value written to ports to test existence. PC-style ports will * return the value written. AT-style ports will return 0. so why not * make them the same ? */ #define LP_DUMMY 0x00 /* * This is the port delay time. Your mileage may vary. * It is used only in the lp_init() routine. */ #define LP_DELAY 150000 /* * function prototypes */ extern long lp_init(long); #endif lpg-0.4.examples/input.c010060000005330001752000000056060573235552000156200ustar00greghlinux00002640000002/* * INP.C - A demonstration program for ncurses. * This program is originally distributed as a part of * the * * AUTHOR: Sven van der Meer (vdmeer@cs.tu-berlin.de) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License,or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include /* always needed */ #include /* malloc is defined there */ void vdmerase (WINDOW *); /* for erasing the screen, werase has some probs */ WINDOW *maskwin; WINDOW *findwin; void main() { char *ptr=(char *)malloc(255); /* the pointer and 255 Byte of memory for it */ if(!(stdscr=initscr())){ /* don't forget this!!! */ fprintf(stderr,"inp: initscr() failed\n\n"); exit (1); } if (!(findwin=newwin(3,37,9,21))){ /* open a window with error check */ fprintf(stderr,"inp: can't open findwin\n\n"); endwin(); exit (1); } if (!(maskwin=newwin(1,21,10,35))){ /* open a window with error check */ fprintf(stderr,"inp: can't open maskwin\n\n"); endwin(); exit (1); } start_color(); /* check for color and initialize the color or attributes */ if (has_colors()){ init_pair(1,COLOR_WHITE,COLOR_RED); init_pair(2,COLOR_BLACK,COLOR_WHITE); wattrset(findwin,COLOR_PAIR(2)); wattrset(maskwin,COLOR_PAIR(1)); } else{ wattrset(findwin,A_REVERSE); wattrset(maskwin,A_NORMAL); } vdmerase(findwin); /* erase the windows, this will show the colors, too */ vdmerase(maskwin); box(findwin,0,0); /* draw a box around the window */ mvwaddstr(findwin,1,2,"Inputstring: "); /* print this to the window */ keypad(stdscr,TRUE); /* enable keypad and cursor keys */ timeout(-1); /* don't wait on input */ nonl(); /* no newline translation */ wnoutrefresh(findwin); wnoutrefresh(maskwin); doupdate(); /* show the windows */ mvwgetstr(maskwin,0,0,ptr); /* wait for input */ delwin(maskwin); /* delete the windows and free up the resources */ delwin(findwin); endwin(); /* end ncurses */ printf("The input was: %s\n",ptr); /* print out the input */ free(ptr); /* free up the ptr */ return; /* exit */ } void vdmerase (WINDOW *win) { int y,x; for (y=0;y<=win->_maxy;y++) for (x=0;x<=win->_maxx;x++) (chtype *)win->_line[y][x]=' '|win->_attrs; win->_curx = win->_cury = 0; touchwin(win); return; } lpg-0.4.examples/screen.c010060000005330001752000000112140573235554500157370ustar00greghlinux00002640000002/* * Screen.C - A demonstration program for ncurses. * This program is originally distributed as a part of * the * * AUTHOR: Sven van der Meer (vdmeer@cs.tu-berlin.de) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License,or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include #include void init_screen(); void end_screen(); void vdmerase(WINDOW *); void usage(); void winsizech(); WINDOW *leftwin; WINDOW *rightwin; int todo; void main (int argc, char *argv[]) { if(strcmp(argv[1],NULL)>=0){ usage(); } todo=atoi(argv[1]); signal(SIGWINCH,winsizech); init_screen(); while(!getch()) ; end_screen(); exit(0); } void init_screen() { int mycols=0, myrows=0; int leftcol=0, leftrow=0, rightcol=0, rightrow=0; if(!(stdscr=initscr())){ fprintf(stderr,"type: initscr() failed\n\n"); exit(1); } switch(todo){ case 1: myrows=22; mycols=77; leftrow=((LINES-myrows)/2); leftcol=((COLS-mycols)/2); rightrow=leftrow; rightcol=leftcol; break; case 2: myrows=LINES-2; mycols=(COLS-6)/2; leftrow=1; leftcol=2; rightrow=1; rightcol=4+mycols; break; case 3: myrows=(LINES/2+LINES/4); mycols=(COLS/2+COLS/4); leftrow=((LINES-myrows)/2); leftcol=((COLS-2)-mycols)/2; mycols=(mycols/2); rightrow=leftrow; rightcol=leftcol+2+mycols; break; default: usage(); } if (!(leftwin=newwin(myrows,mycols,leftrow,leftcol))){ fprintf(stderr,"fileview: can't open dir_win\n\n"); endwin(); exit(1); } if (!(rightwin=newwin(myrows,mycols,rightrow,rightcol))){ fprintf(stderr,"fileview: can't open file_win\n\n"); endwin(); exit (1); } start_color(); if (has_colors()){ init_pair(1,COLOR_WHITE,COLOR_RED); wattrset(leftwin,COLOR_PAIR(1)); wattrset(rightwin,COLOR_PAIR(1)); } else{ wattrset(leftwin,A_REVERSE); wattrset(rightwin,A_REVERSE); } vdmerase(leftwin); vdmerase(rightwin); noecho(); nodelay(stdscr,FALSE); cbreak(); curs_set(FALSE); keypad(stdscr,TRUE); mvwprintw(leftwin,1,1,"LINES: %i, COLS: %i",LINES,COLS); mvwprintw(leftwin,2,1,"Nlines: %i, Ncols: %i",myrows,mycols); mvwprintw(leftwin,3,1,"Begy: %i, Begx: %i",leftrow,leftcol); mvwaddstr(leftwin,5,1,"Press any key to quit"); mvwprintw(rightwin,1,1,"LINES: %i, COLS: %i",LINES,COLS); mvwprintw(rightwin,2,1,"Nlines: %i, Ncols: %i",myrows,mycols); mvwprintw(rightwin,3,1,"Begy: %i, Begx: %i",rightrow,rightcol); mvwaddstr(rightwin,5,1,"Press any key to quit"); wnoutrefresh(leftwin); wnoutrefresh(rightwin); doupdate(); } void end_screen() { delwin(leftwin); delwin(rightwin); curs_set(TRUE); endwin(); } void vdmerase (WINDOW *win) { int y,x; for (y=0;y<=win->_maxy;y++) for (x=0;x<=win->_maxx;x++) (chtype *)win->_line[y][x]=' '|win->_attrs; win->_curx = win->_cury = 0; touchwin(win); return; } void usage() { printf("\nusage: screen[1|2|3]\n"); printf("\n 1 = opens a window with 22 lines and 70 columns in the"); printf("\n middle of the screen."); printf("\n 2 = opens 2 windows with one line free on top and bottom"); printf("\n and two columns free on the left and on the right side"); printf("\n of the screen and two columns free between them."); printf("\n 3 = opens two windows, where for each window the number of"); printf("\n lines is 75%% from LINES and the number of columns is"); printf("\n 43%% from COLS"); printf("\n\n"); exit(0); } /* * Signal handler for SIGWINCH. When this signal is received, * we clean up all windows (delwin), then call endwin and * reinitialize the whole program. it's not fine but it works. * For 'real' programs we need some better functions I think. * */ void winsizech() { end_screen(); init_screen(); signal(SIGWINCH,winsizech); } lpg-0.4.examples/calc.c010060000005330001752000000217030573235561700153660ustar00greghlinux00002640000002/* * CALC.C - A demonstration program for ncurses. * This program is originally distributed as a part of * the * * AUTHOR: Sven van der Meer (vdmeer@cs.tu-berlin.de) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License,or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include /* My background window has 22 rows and 70 columns. These * two defines are logical coordinates to open the window * in the middle of the screen, whatever dimension it has. * TYPE_ROW is the beginning row for my program and TYPE_COL * the beginning column. Every call to newwin(...) will check * these two defines. */ #define CALC_ROW (int) ((LINES-23)/2) #define CALC_COL (int) ((COLS-28)/2) #define ROW 5 #define COL 3 #define LEN 5 #define HEI 3 /* * Global variables. I need three windows (one for the red box, * one for the frame and one for the real output). Beg is for * the output as offset in s[]. Scroll is an enum for calls to * scroll_s (I hate to use integers for this). * s[] is defined in type.h as: * char *s[] = { }; */ WINDOW *screen_win; WINDOW *calc_win; /* * Local function prototypes. * init_type does the ncurses initializing * end_type does the exit for type * vdmerase will erase a window with blanks (I had problems * with the ncurses erase functions, so I wrote my * function). * scroll_s will do the scrolling (UP or DOWN). * clear_line will send space characters from the current * cursor position up to * the length from int. * winsizech() is a signalhandler for SIGWINCH. this signal * will be caught when the screen size has changed * (resized xterm e.g.). */ void vdmerase(WINDOW *); void init_calc(); void end_calc(); void vdmbox(WINDOW *, int, int, int, int, int, int); /* * The main function. */ void main () { bool okloop=TRUE; /* ncurses initializing */ init_calc(); /* ok, the screen has a white window with a box and a red * border around it. * Our main loop. Wait for pressed keys. When the user pressed * 'q' or 'Q' then exit the program. On cursor down or 'd' or 'D' * scroll the text in the window one line down, on cursor up or * 'u' or 'U' one line up. On every other key do nothing. */ while(okloop){ switch(getch()){ case 'q': case 'Q': okloop=FALSE; default : break; } } /* clean uop end exit */ end_calc(); exit(0); } /* * init_type initialize the ncurses data structures, create the * needed windows, print them on screen and set some * usefull options. * */ void init_calc() { int fg, bg; /* don't forget this when using ncurses!!! */ if(!(stdscr=initscr())){ fprintf(stderr,"calc: initscr() failed\n\n"); exit (1); } /* check screen size. we need 20 lines and 18 columns */ if ((LINES<20)||(COLS<18)){ fprintf(stderr,"calc: screen to small\n\n"); endwin(); exit (1); } /* now we open our three windows */ if (!(screen_win=newwin(0,0,0,0))){ fprintf(stderr,"calc: can't open screen_win\n\n"); endwin(); exit (1); } if (!(calc_win=newwin(22,26,CALC_ROW,CALC_COL))){ fprintf(stderr,"calc: can't open calc_win\n\n"); endwin(); exit (1); } /* ok windows are opened, check for color */ start_color(); if (has_colors()){ /* fine we have colors, define color_pairs for foreground * and background colors */ init_pair(1,COLOR_BLACK,COLOR_BLUE); init_pair(2,COLOR_BLACK,COLOR_WHITE); init_pair(3,COLOR_WHITE,COLOR_WHITE); /* now use the defined color_pairs for the windows */ wattrset(screen_win,COLOR_PAIR(1)); wattrset(calc_win,COLOR_PAIR(2)); } else{ /* ohh, no color (maybe a vt100 or xterm). ok we use b&w * attributes instead */ wattrset(screen_win,A_REVERSE); wattrset(calc_win,A_BOLD); } /* now clear the windows to get the attributes visible * (in memory not on the screen). */ vdmerase(screen_win); vdmerase(calc_win); /* wborder with spaces will only paint the border red */ wborder(screen_win,' ',' ',' ',' ',' ',' ',' ',' '); /* and now the real box characters */ vdmbox(calc_win,COLOR_PAIR(3)|A_STANDOUT,COLOR_PAIR(2), 0,0,calc_win->_maxx,calc_win->_maxy); fg=COLOR_PAIR(2); bg=COLOR_PAIR(3)|A_BOLD; vdmbox(calc_win,fg,bg,COL, ROW, COL+LEN-1, ROW+HEI-1); /* Num */ vdmbox(calc_win,fg,bg,COL+LEN, ROW, COL+2*LEN-1, ROW+HEI-1); /* / */ vdmbox(calc_win,fg,bg,COL+2*LEN, ROW, COL+3*LEN-1, ROW+HEI-1); /* * */ vdmbox(calc_win,fg,bg,COL+3*LEN, ROW, COL+4*LEN-1, ROW+HEI-1); /* - */ vdmbox(calc_win,fg,bg,COL, ROW+HEI, COL+LEN-1, ROW+2*HEI-1);/* 7 */ vdmbox(calc_win,fg,bg,COL+LEN, ROW+HEI, COL+2*LEN-1, ROW+2*HEI-1);/* 8 */ vdmbox(calc_win,fg,bg,COL+2*LEN, ROW+HEI, COL+3*LEN-1, ROW+2*HEI-1);/* 9 */ vdmbox(calc_win,fg,bg,COL, ROW+2*HEI, COL+LEN-1, ROW+3*HEI-1);/* 4 */ vdmbox(calc_win,fg,bg,COL+LEN, ROW+2*HEI, COL+2*LEN-1, ROW+3*HEI-1);/* 5 */ vdmbox(calc_win,fg,bg,COL+2*LEN, ROW+2*HEI, COL+3*LEN-1, ROW+3*HEI-1);/* 6 */ vdmbox(calc_win,fg,bg,COL, ROW+3*HEI, COL+LEN-1, ROW+4*HEI-1);/* 1 */ vdmbox(calc_win,fg,bg,COL+LEN, ROW+3*HEI, COL+2*LEN-1, ROW+4*HEI-1);/* 2 */ vdmbox(calc_win,fg,bg,COL+2*LEN, ROW+3*HEI, COL+3*LEN-1, ROW+4*HEI-1);/* 3 */ vdmbox(calc_win,fg,bg,COL+3*LEN, ROW+HEI, COL+4*LEN-1, ROW+3*HEI-1);/* + */ vdmbox(calc_win,fg,bg,COL+3*LEN, ROW+3*HEI, COL+4*LEN-1, ROW+5*HEI-1);/* = */ vdmbox(calc_win,fg,bg,COL, ROW+4*HEI, COL+2*LEN-1, ROW+5*HEI-1);/* 0 */ vdmbox(calc_win,fg,bg,COL+2*LEN, ROW+4*HEI, COL+3*LEN-1, ROW+5*HEI-1);/* . */ mvwaddch(calc_win,ROW+1, COL+LEN+2, '/'); mvwaddch(calc_win,ROW+1, COL+2*LEN+2, '*'); mvwaddch(calc_win,ROW+1, COL+3*LEN+2, '-'); mvwaddch(calc_win,ROW+HEI+1, COL+2, '7'); mvwaddch(calc_win,ROW+HEI+1, COL+LEN+2, '8'); mvwaddch(calc_win,ROW+HEI+1, COL+2*LEN+2, '9'); mvwaddch(calc_win,ROW+2*HEI+1, COL+2, '4'); mvwaddch(calc_win,ROW+2*HEI+1, COL+LEN+2, '5'); mvwaddch(calc_win,ROW+2*HEI+1, COL+2*LEN+2, '6'); mvwaddch(calc_win,ROW+3*HEI+1, COL+2, '1'); mvwaddch(calc_win,ROW+3*HEI+1, COL+LEN+2, '2'); mvwaddch(calc_win,ROW+3*HEI+1, COL+2*LEN+2, '3'); mvwaddch(calc_win,ROW+HEI+2, COL+3*LEN+2, '+'); mvwaddch(calc_win,ROW+3*HEI+2, COL+3*LEN+2, '='); mvwaddch(calc_win,ROW+4*HEI+1, COL+LEN, '0'); mvwaddch(calc_win,ROW+4*HEI+1, COL+2*LEN+2, ','); vdmbox(calc_win,fg,bg,3,2,22,4); wattrset(calc_win,COLOR_PAIR(2)|A_REVERSE); mvwaddstr(calc_win,3,4,"012345678901234567"); wattrset(calc_win,COLOR_PAIR(2)); /* Now the terminal options. * noecho the user typed characters, don't wait for input, * make cursor invisible, don't wait for carriage return * while waiting for input and enable the keypad */ noecho(); nodelay(stdscr,FALSE); cbreak(); curs_set(FALSE); keypad(stdscr,TRUE); /* all window manipulations are done in the memory * now we are going to get in on the physical screen. * wnoutrefresh does everything in the memory, too, and * doupdate will paint our screen!!! */ wnoutrefresh(screen_win); wnoutrefresh(calc_win); doupdate(); } /* The user wants to terminate the program, ok clean up. * Delete all opened windows and make the cursor visible. * At least call endwin. */ void end_calc() { delwin(screen_win); delwin(calc_win); curs_set(TRUE); vdmerase(stdscr); refresh(); endwin(); } /* * With 'erase' and 'werase' from ncurses I don't get white * spaces on black background (any idea why?), so I use * my own erase function. * This goes deep in the structure WINDOW, so I don't recommend * to use this function!!! */ void vdmerase (WINDOW *win) { int y,x; for (y=0;y<=win->_maxy;y++) for (x=0;x<=win->_maxx;x++) (chtype *)win->_line[y][x]=' '|win->_attrs; win->_curx = win->_cury = 0; touchwin(win); return; } void vdmbox(WINDOW *win, int fg, int bg, int begx, int begy, int maxx, int maxy) { int x,y; wattrset(win,fg); mvwaddch(win,begy,begx,ACS_ULCORNER); mvwaddch(win,maxy,begx,ACS_LLCORNER); wattrset(win,bg); mvwaddch(win,begy,maxx,ACS_URCORNER); mvwaddch(win,maxy,maxx,ACS_LRCORNER); for(x=begx+1;x #include #define FIFO_FILE "MYFIFO" int main(int argc, char *argv[]) { FILE *fp; if ( argc != 2 ) { printf("USAGE: fifoclient [string]\n"); exit(1); } if((fp = fopen(FIFO_FILE, "w")) == NULL) { perror("fopen"); exit(1); } fputs(argv[1], fp); fclose(fp); return(0); } lpg-0.4.examples/ipc/fifoserver.c010060000005330001752000000014060573723115400174010ustar00greghlinux00002640000002/***************************************************************************** Excerpt from "Linux Programmer's Guide - Chapter 6" (C)opyright 1994-1995, Scott Burkett ***************************************************************************** MODULE: fifoserver.c *****************************************************************************/ #include #include #include #include #include #define FIFO_FILE "MYFIFO" int main(void) { FILE *fp; char readbuf[80]; /* Create the FIFO if it does not exist */ umask(0); mknod(FIFO_FILE, S_IFIFO|0666, 0); while(1) { fp = fopen(FIFO_FILE, "r"); fgets(readbuf, 80, fp); printf("Received string: %s\n", readbuf); fclose(fp); } return(0); } lpg-0.4.examples/ipc/msgtool.c010060000005330001752000000055630573723115400167230ustar00greghlinux00002640000002/***************************************************************************** Excerpt from "Linux Programmer's Guide - Chapter 6" (C)opyright 1994-1995, Scott Burkett ***************************************************************************** MODULE: msgtool.c ***************************************************************************** A command line tool for tinkering with SysV style Message Queues *****************************************************************************/ #include #include #include #include #include #include #define MAX_SEND_SIZE 80 struct mymsgbuf { long mtype; char mtext[MAX_SEND_SIZE]; }; void send_message(int qid, struct mymsgbuf *qbuf, long type, char *text); void read_message(int qid, struct mymsgbuf *qbuf, long type); void remove_queue(int qid); void change_queue_mode(int qid, char *mode); void usage(void); int main(int argc, char *argv[]) { key_t key; int msgqueue_id; struct mymsgbuf qbuf; if(argc == 1) usage(); /* Create unique key via call to ftok() */ key = ftok(".", 'm'); /* Open the queue - create if necessary */ if((msgqueue_id = msgget(key, IPC_CREAT|0660)) == -1) { perror("msgget"); exit(1); } switch(tolower(argv[1][0])) { case 's': send_message(msgqueue_id, (struct mymsgbuf *)&qbuf, atol(argv[2]), argv[3]); break; case 'r': read_message(msgqueue_id, &qbuf, atol(argv[2])); break; case 'd': remove_queue(msgqueue_id); break; case 'm': change_queue_mode(msgqueue_id, argv[2]); break; default: usage(); } return(0); } void send_message(int qid, struct mymsgbuf *qbuf, long type, char *text) { /* Send a message to the queue */ printf("Sending a message ...\n"); qbuf->mtype = type; strcpy(qbuf->mtext, text); if((msgsnd(qid, (struct msgbuf *)qbuf, strlen(qbuf->mtext)+1, 0)) ==-1) { perror("msgsnd"); exit(1); } } void read_message(int qid, struct mymsgbuf *qbuf, long type) { /* Read a message from the queue */ printf("Reading a message ...\n"); qbuf->mtype = type; msgrcv(qid, (struct msgbuf *)qbuf, MAX_SEND_SIZE, type, 0); printf("Type: %ld Text: %s\n", qbuf->mtype, qbuf->mtext); } void remove_queue(int qid) { /* Remove the queue */ msgctl(qid, IPC_RMID, 0); } void change_queue_mode(int qid, char *mode) { struct msqid_ds myqueue_ds; /* Get current info */ msgctl(qid, IPC_STAT, &myqueue_ds); /* Convert and load the mode */ sscanf(mode, "%ho", &myqueue_ds.msg_perm.mode); /* Update the mode */ msgctl(qid, IPC_SET, &myqueue_ds); } void usage(void) { fprintf(stderr, "msgtool - A utility for tinkering with msg queues\n"); fprintf(stderr, "\nUSAGE: msgtool (s)end \n"); fprintf(stderr, " (r)ecv \n"); fprintf(stderr, " (d)elete\n"); fprintf(stderr, " (m)ode \n"); exit(1); } lpg-0.4.examples/ipc/pipe.c010060000005330001752000000020220573723115400161570ustar00greghlinux00002640000002/***************************************************************************** Excerpt from "Linux Programmer's Guide - Chapter 6" (C)opyright 1994-1995, Scott Burkett ***************************************************************************** MODULE: pipe.c *****************************************************************************/ #include #include #include int main(void) { int fd[2], nbytes; pid_t childpid; char string[] = "Hello, world!\n"; char readbuffer[80]; pipe(fd); if((childpid = fork()) == -1) { perror("fork"); exit(1); } if(childpid == 0) { /* Child process closes up input side of pipe */ close(fd[0]); /* Send "string" through the output side of pipe */ write(fd[1], string, strlen(string)); exit(0); } else { /* Parent process closes up output side of pipe */ close(fd[1]); /* Read in a string from the pipe */ nbytes = read(fd[0], readbuffer, sizeof(readbuffer)); printf("Received string: %s", readbuffer); } return(0); } lpg-0.4.examples/ipc/popen1.c010060000005330001752000000015110573723115400164260ustar00greghlinux00002640000002/***************************************************************************** Excerpt from "Linux Programmer's Guide - Chapter 6" (C)opyright 1994-1995, Scott Burkett ***************************************************************************** MODULE: popen1.c *****************************************************************************/ #include #define MAXSTRS 5 int main(void) { int cntr; FILE *pipe_fp; char *strings[MAXSTRS] = { "echo", "bravo", "alpha", "charlie", "delta"}; /* Create one way pipe line with call to popen() */ if (( pipe_fp = popen("sort", "w")) == NULL) { perror("popen"); exit(1); } /* Processing loop */ for(cntr=0; cntr int main(void) { FILE *pipein_fp, *pipeout_fp; char readbuf[80]; /* Create one way pipe line with call to popen() */ if (( pipein_fp = popen("ls", "r")) == NULL) { perror("popen"); exit(1); } /* Create one way pipe line with call to popen() */ if (( pipeout_fp = popen("sort", "w")) == NULL) { perror("popen"); exit(1); } /* Processing loop */ while(fgets(readbuf, 80, pipein_fp)) fputs(readbuf, pipeout_fp); /* Close the pipes */ pclose(pipein_fp); pclose(pipeout_fp); return(0); } lpg-0.4.examples/ipc/popen3.c010060000005330001752000000017260573723115400164400ustar00greghlinux00002640000002/***************************************************************************** Excerpt from "Linux Programmer's Guide - Chapter 6" (C)opyright 1994-1995, Scott Burkett ***************************************************************************** MODULE: popen3.c *****************************************************************************/ #include int main(int argc, char *argv[]) { FILE *pipe_fp, *infile; char readbuf[80]; if( argc != 3) { fprintf(stderr, "USAGE: popen3 [command] [filename]\n"); exit(1); } /* Open up input file */ if (( infile = fopen(argv[2], "rt")) == NULL) { perror("fopen"); exit(1); } /* Create one way pipe line with call to popen() */ if (( pipe_fp = popen(argv[1], "w")) == NULL) { perror("popen"); exit(1); } /* Processing loop */ do { fgets(readbuf, 80, infile); if(feof(infile)) break; fputs(readbuf, pipe_fp); } while(!feof(infile)); fclose(infile); pclose(pipe_fp); return(0); } lpg-0.4.examples/ipc/semstat.c010060000005330001752000000034030573723115400167060ustar00greghlinux00002640000002/***************************************************************************** Excerpt from "Linux Programmer's Guide - Chapter 6" (C)opyright 1994-1995, Scott Burkett ***************************************************************************** MODULE: semstat.c ***************************************************************************** A companion command line tool for the semtool package. semstat displays the current value of all semaphores in the set created by semtool. *****************************************************************************/ #include #include #include #include #include int get_sem_count(int sid); void show_sem_usage(int sid); int get_sem_count(int sid); void dispval(int sid); int main(int argc, char *argv[]) { key_t key; int semset_id; /* Create unique key via call to ftok() */ key = ftok(".", 's'); /* Open the semaphore set - do not create! */ if((semset_id = semget(key, 1, 0666)) == -1) { printf("Semaphore set does not exist\n"); exit(1); } show_sem_usage(semset_id); return(0); } void show_sem_usage(int sid) { int cntr=0, maxsems, semval; maxsems = get_sem_count(sid); while(cntr < maxsems) { semval = semctl(sid, cntr, GETVAL, 0); printf("Semaphore #%d: --> %d\n", cntr, semval); cntr++; } } int get_sem_count(int sid) { int rc; struct semid_ds mysemds; union semun semopts; /* Get current values for internal data structure */ semopts.buf = &mysemds; if((rc = semctl(sid, 0, IPC_STAT, semopts)) == -1) { perror("semctl"); exit(1); } /* return number of semaphores in set */ return(semopts.buf->sem_nsems); } void dispval(int sid) { int semval; semval = semctl(sid, 0, GETVAL, 0); printf("semval is %d\n", semval); } lpg-0.4.examples/ipc/semtool.c010060000005330001752000000122500573723115400167100ustar00greghlinux00002640000002/***************************************************************************** Excerpt from "Linux Programmer's Guide - Chapter 6" (C)opyright 1994-1995, Scott Burkett ***************************************************************************** MODULE: semtool.c ***************************************************************************** A command line tool for tinkering with SysV style Semaphore Sets *****************************************************************************/ #include #include #include #include #include #include #define SEM_RESOURCE_MAX 1 void opensem(int *sid, key_t key); void createsem(int *sid, key_t key, int members); void locksem(int sid, int member); void unlocksem(int sid, int member); void removesem(int sid); unsigned short get_member_count(int sid); int getval(int sid, int member); void dispval(int sid, int member); void changemode(int sid, char *mode); void usage(void); int main(int argc, char *argv[]) { key_t key; int semset_id; if(argc == 1) usage(); /* Create unique key via call to ftok() */ key = ftok(".", 's'); switch(tolower(argv[1][0])) { case 'c': if(argc != 3) usage(); createsem(&semset_id, key, atoi(argv[2])); break; case 'l': if(argc != 3) usage(); opensem(&semset_id, key); locksem(semset_id, atoi(argv[2])); break; case 'u': if(argc != 3) usage(); opensem(&semset_id, key); unlocksem(semset_id, atoi(argv[2])); break; case 'd': opensem(&semset_id, key); removesem(semset_id); break; case 'm': opensem(&semset_id, key); changemode(semset_id, argv[2]); break; default: usage(); } exit(0); /*NOTREACHED*/ } void opensem(int *sid, key_t key) { /* Open the semaphore set - do not create! */ if((*sid = semget(key, 0, 0666)) == -1) { printf("Semaphore set does not exist!\n"); exit(1); } } void createsem(int *sid, key_t key, int members) { int cntr; union semun semopts; if(members > SEMMSL) { printf("Sorry, max number of semaphores in a set is %d\n", SEMMSL); exit(1); } printf("Attempting to create new semaphore set with %d members\n", members); if((*sid = semget(key, members, IPC_CREAT|IPC_EXCL|0666)) == -1) { fprintf(stderr, "Semaphore set already exists!\n"); exit(1); } semopts.val = SEM_RESOURCE_MAX; /* Initialize all members (could be done with SETALL) */ for(cntr=0; cntr(get_member_count(sid)-1)) { fprintf(stderr, "semaphore member %d out of range\n", member); return; } /* Attempt to lock the semaphore set */ if(!getval(sid, member)) { fprintf(stderr, "Semaphore resources exhausted (no lock)!\n"); exit(1); } sem_lock.sem_num = member; if((semop(sid, &sem_lock, 1)) == -1) { fprintf(stderr, "Lock failed\n"); exit(1); } else printf("Semaphore resources decremented by one (locked)\n"); dispval(sid, member); } void unlocksem(int sid, int member) { struct sembuf sem_unlock={ member, 1, IPC_NOWAIT}; int semval; if( member<0 || member>(get_member_count(sid)-1)) { fprintf(stderr, "semaphore member %d out of range\n", member); return; } /* Is the semaphore set locked? */ semval = getval(sid, member); if(semval == SEM_RESOURCE_MAX) { fprintf(stderr, "Semaphore not locked!\n"); exit(1); } sem_unlock.sem_num = member; /* Attempt to lock the semaphore set */ if((semop(sid, &sem_unlock, 1)) == -1) { fprintf(stderr, "Unlock failed\n"); exit(1); } else printf("Semaphore resources incremented by one (unlocked)\n"); dispval(sid, member); } void removesem(int sid) { semctl(sid, 0, IPC_RMID, 0); printf("Semaphore set removed\n"); } unsigned short get_member_count(int sid) { union semun semopts; struct semid_ds mysemds; semopts.buf = &mysemds; /* Return number of members in the semaphore set */ return(semopts.buf->sem_nsems); } int getval(int sid, int member) { int semval; semval = semctl(sid, member, GETVAL, 0); return(semval); } void changemode(int sid, char *mode) { int rc; union semun semopts; struct semid_ds mysemds; /* Get current values for internal data structure */ semopts.buf = &mysemds; rc = semctl(sid, 0, IPC_STAT, semopts); if (rc == -1) { perror("semctl"); exit(1); } printf("Old permissions were %o\n", semopts.buf->sem_perm.mode); /* Change the permissions on the semaphore */ sscanf(mode, "%ho", &semopts.buf->sem_perm.mode); /* Update the internal data structure */ semctl(sid, 0, IPC_SET, semopts); printf("Updated...\n"); } void dispval(int sid, int member) { int semval; semval = semctl(sid, member, GETVAL, 0); printf("semval for member %d is %d\n", member, semval); } void usage(void) { fprintf(stderr, "semtool - A utility for tinkering with semaphores\n"); fprintf(stderr, "\nUSAGE: semtool4 (c)reate \n"); fprintf(stderr, " (l)ock \n"); fprintf(stderr, " (u)nlock \n"); fprintf(stderr, " (d)elete\n"); fprintf(stderr, " (m)ode \n"); exit(1); } members); if((*sid = semget(key, members, IPC_CREAT|IPC_EXCL|0666)) == -1) { fprintf(stderr, "Semaphore set already exists!\n"); exit(1); } semopts.val = SEM_RESOURCE_MAX; /* Initialize all members (could be done with SETALL) */ for(cntr=0; cntr #include #include #include #include #include #define SEGSIZE 100 void writeshm(int shmid, char *segptr, char *text); void readshm(int shmid, char *segptr); void removeshm(int shmid); void changemode(int shmid, char *mode); void usage(void); int main(int argc, char *argv[]) { key_t key; int shmid; char *segptr; if(argc == 1) usage(); /* Create unique key via call to ftok() */ key = ftok(".", 'S'); /* Open the shared memory segment - create if necessary */ if((shmid = shmget(key, SEGSIZE, IPC_CREAT|IPC_EXCL|0666)) == -1) { printf("Shared memory segment exists - opening as client\n"); /* Segment probably already exists - try as a client */ if((shmid = shmget(key, SEGSIZE, 0)) == -1) { perror("shmget"); exit(1); } } else { printf("Creating new shared memory segment\n"); } /* Attach (map) the shared memory segment into the current process */ if((segptr = shmat(shmid, 0, 0)) == (char *)-1) { perror("shmat"); exit(1); } switch(tolower(argv[1][0])) { case 'w': writeshm(shmid, segptr, argv[2]); break; case 'r': readshm(shmid, segptr); break; case 'd': removeshm(shmid); break; case 'm': changemode(shmid, argv[2]); break; default: usage(); } return(0); } void writeshm(int shmid, char *segptr, char *text) { strcpy(segptr, text); printf("Done...\n"); } void readshm(int shmid, char *segptr) { printf("segptr: %s\n", segptr); } void removeshm(int shmid) { shmctl(shmid, IPC_RMID, 0); printf("Shared memory segment marked for deletion\n"); } void changemode(int shmid, char *mode) { struct shmid_ds myshmds; /* Get current values for internal data structure */ shmctl(shmid, IPC_STAT, &myshmds); /* Display old permissions */ printf("Old permissions were: %o\n", myshmds.shm_perm.mode); /* Convert and load the mode */ sscanf(mode, "%ho", &myshmds.shm_perm.mode); /* Update the mode */ shmctl(shmid, IPC_SET, &myshmds); printf("New permissions are : %o\n", myshmds.shm_perm.mode); } void usage(void) { fprintf(stderr, "shmtool - A utility for tinkering with shared memory\n"); fprintf(stderr, "\nUSAGE: shmtool (w)rite \n"); fprintf(stderr, " (r)ead\n"); fprintf(stderr, " (d)elete\n"); fprintf(stderr, " (m)ode change \n"); exit(1); } lpg-0.4.examples/ipc/fifoclient010070000005330001752000000200000573754164600171320ustar00greghlinux00002640000002d -̀\ `D$4 ` PKPq_[̀USAGE: fifoclient [string] wMYFIFOfopenUVS]u tht=_j_hh_Ãuh_j_SFP_S_1e[^]ÐUS| =| tЃ;u]]ÐUSH u1=L t@ %d UWVS}1W?ƃ9}!jj SW`PSh_C9|e[^_]semctlU,EURjjP}`uhIk_jL_E]semval is %d UEjj jP2`Ph?_]ÐUS| =| tЃ;u]]ÐUSH u1=L t@