├── .gitignore.ref ├── 16_unali ├── 16_unali.c └── makefile ├── Poing ├── Ping.c ├── Poing.h ├── Pong.c └── makefile ├── README ├── adjtime ├── adjtime.c ├── adjtime_call.c ├── adjtime_call.h ├── adjustment ├── makefile └── prof_adjtime.c ├── asc ├── asc.c └── makefile ├── ask ├── ask.c └── makefile ├── boolean └── makefile ├── byte_swapping ├── bs.c └── makefile ├── catlock ├── catlock.c └── makefile ├── cirtail ├── circul.c ├── circul.h ├── cirpipe.c ├── cirtail.c ├── makefile └── uncircular.c ├── delay ├── delay.c └── makefile ├── delta_time ├── delta_time.c └── makefile ├── dos2unix ├── dos2unix.c ├── makefile └── unix2dos.c ├── dt ├── dt.c ├── makefile └── settime.c ├── dynlist ├── dynlist.c ├── dynlist.h ├── makefile └── tdl.c ├── enquire ├── enquire.c ├── float.h ├── limits.h └── makefile ├── font_size ├── font_size.c ├── list_fonts └── makefile ├── forker ├── client.c ├── forker.c ├── forker_messages.h └── makefile ├── formfeed ├── formfeed.c └── makefile ├── fread_float ├── flint.c ├── fread_float.c ├── fwrite.c └── makefile ├── get_line ├── get_line.c ├── get_line.h └── makefile ├── gettimeofdays ├── gettimeofdays.c └── makefile ├── gorgy ├── gorgy.c ├── makefile ├── serial_spy.c ├── tty.c ├── tty.h ├── udp.c └── udp.h ├── html2ascii ├── html2ascii.c └── makefile ├── init_so ├── makefile ├── module1.c ├── module1.h ├── module2.c ├── module2.h └── try.c ├── ipm ├── makefile └── tipm.c ├── ipx ├── ipx.c └── makefile ├── locale ├── locale.c └── makefile ├── localtime ├── localtime.c └── makefile ├── lzf ├── .gitignore ├── Changes ├── LICENSE ├── Makefile.in ├── README ├── config.h.in ├── configure ├── configure.ac ├── crc32.h ├── cs │ ├── CLZF.cs │ └── README ├── install-sh ├── lzf.c ├── lzf.h ├── lzfP.h ├── lzf_c.c ├── lzf_d.c └── rlzf ├── makefile ├── mallocer ├── lib.c ├── makefile └── mallocer.c ├── man2file ├── makefile └── parse_man.c ├── mapcode ├── compare ├── makefile └── tmc.c ├── mheap ├── makefile └── mheap.c ├── mu ├── makefile └── mu.c ├── mutex ├── makefile ├── mutex.c └── mutex.h ├── name_of ├── makefile └── name_of.c ├── pause ├── makefile └── pause.c ├── pcre ├── makefile ├── tpcre.c ├── tpcre2.c └── tposix2pcre2.c ├── pcrypt ├── makefile └── pcrypt.c ├── putvar ├── makefile └── putvar.c ├── rusage ├── anal_rusage.c ├── makefile ├── rusage.c ├── rusage.h └── t_rusage.c ├── sem_util ├── makefile ├── sem_util.c └── sem_util.h ├── semctl ├── Semctl ├── makefile ├── semctl.c └── semget.c ├── shm ├── makefile └── shm.c ├── sig_util ├── makefile ├── sig_util.c ├── sig_util.h ├── t_pause.c └── t_sig.c ├── socket └── makefile ├── socket_evt └── makefile ├── status ├── makefile └── status.c ├── substit ├── makefile └── substit.c ├── svn_tree ├── callbacks.c ├── callbacks.h ├── makefile ├── svn_includes.h ├── svn_tree.c ├── utilities.c └── utilities.h ├── synchro ├── eti.c ├── gorgy_decode.c ├── gorgy_decode.h ├── makefile ├── synchro.h ├── synchro_client.c ├── synchro_serial.c └── synchro_server.c ├── t_malloc ├── killer.c ├── makefile └── mallocer.c ├── t_time ├── makefile └── t_time.c ├── tcpdump ├── makefile └── tcpdump.c ├── term ├── makefile ├── mterm ├── term.c ├── tty.c └── tty.h ├── time_spy ├── makefile └── time_spy.c ├── timeval └── makefile ├── udp_send ├── makefile └── udp_send.c ├── udpspy ├── makefile ├── udpspy.c ├── util.c └── util.h ├── unlink ├── makefile └── unlink.c ├── vt100 ├── makefile ├── vt100.c └── vt100.h └── wait_evt └── makefile /.gitignore.ref: -------------------------------------------------------------------------------- 1 | # For normal libs 2 | lib 3 | .gitignore 4 | -------------------------------------------------------------------------------- /16_unali/16_unali.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define LEN 50 5 | 6 | int main (int argc, char *argv[]) { 7 | 8 | short s, *ps; 9 | char str[LEN]; 10 | int i; 11 | int v; 12 | 13 | if (argc == 2) { 14 | v = atoi(argv[1]); 15 | } else { 16 | exit (1); 17 | } 18 | 19 | for (i = 0; i < LEN; i++) { 20 | str[i] = (char) v; 21 | } 22 | 23 | printf ("%d : ", v); 24 | for (i = 0; i < 4 ; i++) { 25 | ps = (short*) (&str[i]); 26 | s = *ps; 27 | printf ("%d -> %04hX ", i, s); 28 | } 29 | printf ("\n"); 30 | exit(0); 31 | } 32 | 33 | -------------------------------------------------------------------------------- /16_unali/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | EXES := 16_unali 4 | 5 | include $(TEMPLATES)/c.mk 6 | 7 | -------------------------------------------------------------------------------- /Poing/Ping.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "Poing.h" 5 | 6 | static void error (const char *s) __attribute__ ((noreturn)); 7 | 8 | int main (int argc, char *argv[]) { 9 | soc_token soc = init_soc; 10 | int res; 11 | char buff[BUFF_SIZE]; 12 | soc_length len; 13 | boolean ping_lan; 14 | 15 | /* Parse command line arguments : host_name */ 16 | if (argc != 3) error("Syntax"); 17 | 18 | /* Syntax is Ping lan or Ping host */ 19 | ping_lan = false; 20 | if (strcmp(argv[1], "host") == 0) { 21 | ping_lan = false; 22 | } else if (strcmp(argv[1], "lan") == 0) { 23 | ping_lan = true; 24 | } else { 25 | error("Syntax"); 26 | } 27 | 28 | /* Create socket */ 29 | res = soc_open(&soc, udp_socket); 30 | if (res != SOC_OK) { 31 | perror("soc_open"); 32 | error("Socket creation"); 33 | } 34 | 35 | /* Set destination */ 36 | res = soc_set_dest_name_service(soc, argv[2], ping_lan, PORT_NAME); 37 | if (res != SOC_OK) { 38 | perror("soc_set_dest_service"); 39 | error("Setting destination"); 40 | } 41 | 42 | /* Connect to port */ 43 | res = soc_link_service (soc, PORT_NAME); 44 | if (res != SOC_OK) { 45 | perror("soc_link_service"); 46 | error("Connecting to port"); 47 | } 48 | 49 | /* Send */ 50 | strcpy (buff, "Ping"); 51 | res = soc_send (soc, buff, (soc_length)strlen(buff)); 52 | if (res != SOC_OK) { 53 | perror("soc_send"); 54 | error("Sending message"); 55 | } 56 | 57 | /* Receive */ 58 | len = (soc_length)sizeof(buff); 59 | res = soc_receive (soc, buff, len, FALSE); 60 | if (res != SOC_OK) { 61 | perror("soc_receive"); 62 | error("receiving message"); 63 | } 64 | len = res; 65 | 66 | /* Print */ 67 | buff[len]='\0'; 68 | printf("Received: >%s<\n", buff); 69 | 70 | /* Close socket */ 71 | res = soc_close(&soc); 72 | if (res != SOC_OK) { 73 | perror("soc_close"); 74 | error("Closing socket"); 75 | } 76 | exit(0); 77 | } 78 | 79 | static void error (const char *s) { 80 | printf ("ERROR: %s\nUsage: Ping host or Ping lan \n", s); 81 | exit(1); 82 | } 83 | 84 | -------------------------------------------------------------------------------- /Poing/Poing.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "socket.h" 5 | 6 | #define BUFF_SIZE 500 7 | #define PORT_NAME "test_udp" 8 | 9 | 10 | -------------------------------------------------------------------------------- /Poing/Pong.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "Poing.h" 5 | 6 | static void error (const char *s) __attribute__ ((noreturn)); 7 | 8 | static void error(const char *s); 9 | 10 | int main (int argc, char *argv[] __attribute__ ((unused)) ) { 11 | soc_token soc = init_soc; 12 | int res; 13 | char buff[BUFF_SIZE]; 14 | soc_length len; 15 | 16 | /* Parse command line arguments : no arg */ 17 | if (argc != 1) error("Syntax"); 18 | 19 | /* Create socket */ 20 | res = soc_open(&soc, udp_socket); 21 | if (res != SOC_OK) { 22 | perror("soc_open"); 23 | error("Socket creation"); 24 | } 25 | 26 | /* Connect to port */ 27 | res = soc_link_service (soc, PORT_NAME); 28 | if (res != SOC_OK) { 29 | perror("soc_link_service"); 30 | error("Connecting to port"); 31 | } 32 | 33 | for (;;) { 34 | /* Receive */ 35 | len = (soc_length)sizeof(buff); 36 | res = soc_receive (soc, buff, len, TRUE); 37 | if (res != SOC_OK) { 38 | perror("soc_receive"); 39 | error("Receiving message"); 40 | } 41 | len = res; 42 | 43 | /* Print */ 44 | buff[len]='\0'; 45 | printf("Received: >%s<\n", buff); 46 | 47 | /* Reply */ 48 | strcpy (buff, "Pong"); 49 | res = soc_send (soc, buff, (soc_length)strlen(buff)); 50 | if (res != SOC_OK) { 51 | perror("soc_send"); 52 | error("Sending reply"); 53 | } 54 | } 55 | 56 | /* Close socket 57 | res = soc_close(&soc); 58 | if (res != SOC_OK) { 59 | perror("soc_close"); 60 | error("Closing socket"); 61 | } 62 | */ 63 | 64 | } 65 | 66 | static void error(const char *s) { 67 | printf ("ERROR: %s\nUsage: Pong\n", s); 68 | exit(1); 69 | } 70 | 71 | -------------------------------------------------------------------------------- /Poing/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DINCL := boolean 4 | DLIBA := socket mutex 5 | 6 | EXES := Ping Pong 7 | 8 | include $(TEMPLATES)/c.mk 9 | 10 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | These are my C libraries and programs. 2 | The compilation requires the Makefiles project to be installed. 3 | Because some library sources are in fact links to sources in the ada 4 | project (ada/c) this project is required too. These sources are tagged (A). 5 | Interesting directories are tagged (*). 6 | 7 | Libraries: 8 | boolean(A*) : Boolean type definition 9 | socket(A*) : Socket (TCP/UDP/IPM) blocking or not 10 | socket_evt(A) : Socket with Fd declarations to wait_evt 11 | timeval(A*) : Operations on struct timeval 12 | wait_evt(A*) : Signal hadling and select on Fds 13 | adjtime : System time adjustment 14 | dynlist(*) : Generic dynamic list 15 | get_line : Get lines of text from file 16 | mutex : Pthread mutex 17 | rusage : Unix resource usage 18 | sem_util : Semaphore operations 19 | sig_util : Signal management 20 | vt100 : Console emulator 21 | 22 | Programs: 23 | 16_unali : 10 base to 16 base conversion 24 | asc : ASCII codes 25 | ask : Get answer and convert to lower/upper 26 | byte_swapping : Puts the bytes of a 32 bits integer 27 | catlock : Cat a file or text to a locked file 28 | cirtail : Circular file (of logs) 29 | delay : Wait a bit 30 | delta_time : Delta of system time between hosts 31 | dos2unix : Dos <-> Unix text conversion (CrLf <-> Lf) 32 | dt : Timeval seconds to date conversion 33 | enquire : Analyze number management of libc and math 34 | forker : Forks processes according to udp/tcp requests 35 | formfeed : Issue a formfeed character 36 | fread_float : Read a float at a given offset from a binary file 37 | gettimeofdays : Performance measurement of gettimeofday 38 | gorgy : Simulator of Gorgy clock (udp or serial) 39 | html2ascii : Remove html markers 40 | init_so : Test shared library initialization 41 | ipm : Send a message to an IPM address 42 | ipx : Integer representation of an IP address 43 | locale : Ascii table depending on current locale 44 | localtime : Display local time 45 | mallocer : Check malloc reentrance 46 | man2file : Convert a man file into text file 47 | mu(*) : Binary file editor 48 | name_of : Host <-> IP address resolver 49 | pause : Test pause system call 50 | pcre : Test pcre install and version 51 | pcrypt : Test crypt command 52 | Poing : UDP ping pong 53 | putvar : Getenv 54 | semctl : Semaphore control 55 | shm : List available shared memory addresses 56 | status : Dependancy status of files (like make) 57 | substit : String substitutions in files 58 | svn_tree : Analyse subversion tree (tags/branches) 59 | synchro : Hosts synchronization utilities 60 | tcpdump : Call tcpdump command and format its output 61 | term : Terminal emulator on serial line 62 | time_spy : Udp ping pong to check host time alignment 63 | t_malloc : Malloc tester 64 | t_time : Clock tick evaluation 65 | udpspy(*) : Catch and put UDP/IPM packets 66 | udp_send : Sent UDP packets 67 | unlink : Unkink (remove) a file 68 | 69 | -------------------------------------------------------------------------------- /adjtime/adjtime.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "adjtime_call.h" 5 | 6 | int main(int argc, char *argv[]) { 7 | 8 | struct timeval delta, old_delta, *p_delta; 9 | 10 | float printed_delta; 11 | 12 | if (argc > 2) { 13 | fprintf (stderr, "Syntax error. Usage : adjtime [ ]\n"); 14 | exit (1); 15 | } 16 | 17 | if (argc == 2) { 18 | p_delta = δ 19 | sscanf (argv[1], "%f", &printed_delta); 20 | delta.tv_sec = (time_t)printed_delta; 21 | delta.tv_usec = (printed_delta - (float) delta.tv_sec) * 1000000; 22 | printf ("adjtime (%d.%06d)\n", (int)delta.tv_sec, abs((int)delta.tv_usec)); 23 | } else { 24 | p_delta = (struct timeval*) NULL; 25 | } 26 | 27 | if (adjtime_call (p_delta, &old_delta) != 0) { 28 | exit (1); 29 | } else { 30 | printed_delta = old_delta.tv_sec + (float) old_delta.tv_usec / 1000000.0; 31 | printf ("remaining (%3.06f)\n", printed_delta); 32 | } 33 | 34 | exit (0); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /adjtime/adjtime_call.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "adjtime_call.h" 4 | 5 | 6 | extern int adjtime_call (struct timeval *new_delta, struct timeval *old_delta) { 7 | struct timeval loc_delta; 8 | 9 | /* New delta to set or read only */ 10 | if (new_delta != (struct timeval *)NULL) { 11 | /* New delta to set */ 12 | loc_delta = *new_delta; 13 | if ( (loc_delta.tv_sec == 0) && (loc_delta.tv_usec == 0) ) { 14 | /* (0, 0) does not affect! trick */ 15 | loc_delta.tv_usec = 1; 16 | } 17 | } else { 18 | /* To read value without affecting current delta */ 19 | loc_delta.tv_sec = 0; 20 | loc_delta.tv_usec = 0; 21 | } 22 | 23 | if (adjtime (&loc_delta, old_delta) != 0) { 24 | perror("adjtime"); 25 | return (-1); 26 | } 27 | 28 | /* Restore adjustement if read only */ 29 | if (new_delta == (struct timeval *)NULL) { 30 | if (adjtime (old_delta, (struct timeval*)NULL) != 0) { 31 | perror("adjtime"); 32 | return (-1); 33 | } 34 | } 35 | return (0); 36 | 37 | } 38 | 39 | -------------------------------------------------------------------------------- /adjtime/adjtime_call.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | /* 5 | if new_delta is non NULL -> change adjustement 6 | if new_delta is NULL -> do not change adjustement 7 | if old_delta is non NULL -> fill it with current adjustement 8 | 9 | returns 0 if OK and -1 if error 10 | */ 11 | 12 | extern int adjtime_call (struct timeval *new_delta, struct timeval *old_delta); 13 | 14 | -------------------------------------------------------------------------------- /adjtime/adjustment: -------------------------------------------------------------------------------- 1 | 3/11/94 2 | Rappel des actions correctrices: 3 | - Implementer les seuils (ETI et CS_SYNC) 4 | - Implementer le lissage (ETI et CS_SYNC) 5 | - Nettoyer HRT 6 | 7 | Pour ETI et CS_SYNC, la strategie d'utilisation 8 | d'adjtime devrait etre la suivante: 9 | - Chaque fois qu'on appelle adjtime, l'argument 10 | est conserve. 11 | - Quand un ecart est constate et que la situation 12 | necessite un lissage (init ou non, valeur par 13 | rapport aux seuils): 14 | * Verifier que l'ecart est dans le meme sens 15 | et inferieur en valeur absolue a la correction 16 | en cours (argument conserve) 17 | * Si non, adjtime(ecart constate) 18 | 19 | - Quand l'ecart constate est inferieur au seuil 20 | et que la valeur courante du rattrapage est superieure 21 | au seuil, annuler le rattrapage. 22 | 23 | 4/11/94 24 | Autre proposition d'algorithme: 25 | On n'a pas besoin de concerver l'argument mais 26 | on appelle adjtime(0) a chaque fois. 27 | S0 : Seuil en dessous duquel on ne fait rien 28 | EcartConstate := TReference - Tlocal 29 | EcartEnRattrapage := adjtime(0) 30 | si | EcartConstate - EcartEnRattrapage | >= S0 31 | adjtime(EcartConstate) 32 | 33 | Cout d'un appel adjtime : 0.1 ms environ 34 | -------------------------------------------------------------------------------- /adjtime/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | LIBS := libadjtime 4 | OBJS_libadjtime := adjtime_call 5 | 6 | EXES := adjtime prof_adjtime 7 | LIBS_adjtime := libadjtime 8 | LIBS_prof_adjtime := libadjtime 9 | 10 | include $(TEMPLATES)/c.mk 11 | 12 | -------------------------------------------------------------------------------- /adjtime/prof_adjtime.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "adjtime_call.h" 4 | 5 | int main(void) { 6 | int i, j; 7 | struct timeval t1, t2; 8 | float printed_delta; 9 | 10 | for (i = 0; i < 10; i++) { 11 | t1.tv_sec = i; 12 | t1.tv_usec = 0; 13 | for (j = 0; j < 100; j++) 14 | if (adjtime_call(&t1, &t2) == -1) 15 | exit(0); 16 | printed_delta = t2.tv_sec + (float) t2.tv_usec / 1000000.0; 17 | printf ("remaining (%3.06f)\n", printed_delta); 18 | } 19 | 20 | 21 | for (i = -10; i <= 0; i++) { 22 | t1.tv_sec = i; 23 | t1.tv_usec = 0; 24 | for (j = 0; j < 100; j++) 25 | if (adjtime_call(&t1, &t2) == -1) 26 | exit(0); 27 | printed_delta = t2.tv_sec + (float) t2.tv_usec / 1000000.0; 28 | printf ("remaining (%3.06f)\n", printed_delta); 29 | } 30 | exit(0); 31 | } 32 | 33 | -------------------------------------------------------------------------------- /asc/asc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define ALL 1 5 | #define ONE 0 6 | 7 | static void draw (char *str[], int count, char param); 8 | static void help(char *str[]); 9 | 10 | int main (int argc, char *argv[]) { 11 | 12 | if ( argc < 2 ) help(argv); 13 | else draw (argv, argc, ONE); 14 | exit(0); 15 | } 16 | 17 | static void help (char *str[]) { 18 | printf ("-- usage : \n"); 19 | printf (" ascii [ARG]\n"); 20 | printf (" where ARG is a character or a string\n"); 21 | printf (" if no argument is specified \n"); 22 | printf (" print the whole ascii table\n\n"); 23 | draw (str, ALL, ' '); 24 | } 25 | 26 | static void draw (char *str[], int count, char param) { 27 | int j=0, i=0; 28 | 29 | printf ("+-----------+-----+-----+-----+\n"); 30 | printf ("| character | dec | oct | hex |\n"); 31 | printf ("+-----------+-----+-----+-----+\n"); 32 | 33 | if ( param == ONE ) 34 | { 35 | for ( j = 1; j < count; ) 36 | { 37 | i = 0; 38 | while ( str[j][i] != '\0' ) 39 | { 40 | printf ("| %c | %3d | %3o | %3X |\n", str[j][i], str[j][i], str[j][i], str[j][i]); 41 | i++; 42 | } 43 | if ( j < count - 1) printf ("+-----------+-----+-----+-----+\n"); 44 | j++; 45 | } 46 | } 47 | else 48 | { 49 | for ( i = 32; i < 127; i++) 50 | { 51 | printf ("| %c | %3d | %3o | %3X |\n", i, i, i, i); 52 | } 53 | } 54 | 55 | printf ("+-----------+-----+-----+-----+\n"); 56 | 57 | } 58 | 59 | -------------------------------------------------------------------------------- /asc/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | EXES := asc 4 | 5 | include $(TEMPLATES)/c.mk 6 | 7 | -------------------------------------------------------------------------------- /ask/ask.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define ERROR {printf ("ERROR. Usage %s [ -l | -U ] [ ]\n", argv[0]);\ 6 | exit (1); } 7 | 8 | int main (int argc, char *argv[]) { 9 | int i, j; 10 | char rep[256]; 11 | char *msg; 12 | int to_up, to_lo; 13 | 14 | to_up = 0; 15 | to_lo = 0; 16 | msg = NULL; 17 | if (argc == 1) { 18 | ; 19 | } else if (argc == 2) { 20 | if (strcmp(argv[1], "-l") == 0) { 21 | to_lo = 1; 22 | } else if (strcmp(argv[1], "-U") == 0) { 23 | to_up = 1; 24 | } else { 25 | msg = argv[1]; 26 | } 27 | } else if (argc == 3) { 28 | msg = argv[2]; 29 | if (strcmp(argv[1], "-l") == 0) { 30 | to_lo = 1; 31 | } else if (strcmp(argv[1], "-U") == 0) { 32 | to_up = 1; 33 | } else { 34 | ERROR; 35 | } 36 | } else { 37 | ERROR; 38 | } 39 | 40 | if (msg != NULL) { 41 | printf ("%s", msg); 42 | } 43 | 44 | i = 0; 45 | for (;;) { 46 | rep[i] = (char) getchar(); 47 | if (rep[i] == '\n') break; 48 | i++; 49 | } 50 | 51 | 52 | if (i == 0) { 53 | i = 1; 54 | rep[0] = '-'; 55 | } 56 | rep[i] = '\0'; 57 | 58 | for (j = 0; j < i; j++) { 59 | if (to_lo) { 60 | if ( (rep[j] >= 'A') && (rep[j] <= 'Z') ) { 61 | rep[j] = rep[j] - 'A' + 'a'; 62 | } 63 | } else if (to_up) { 64 | if ( (rep[j] >= 'a') && (rep[j] <= 'z') ) { 65 | rep[j] = rep[j] - 'a' + 'A'; 66 | } 67 | } 68 | } 69 | 70 | printf ("%s\n", rep); 71 | exit(0); 72 | } 73 | 74 | -------------------------------------------------------------------------------- /ask/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | EXES := ask 4 | 5 | include $(TEMPLATES)/c.mk 6 | 7 | -------------------------------------------------------------------------------- /boolean/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | FILES2LINK := boolean.h 4 | LINKFROM := $(HOME)/ada/c 5 | 6 | include $(TEMPLATES)/c.mk 7 | 8 | -------------------------------------------------------------------------------- /byte_swapping/bs.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main (void) { 4 | 5 | int n; 6 | int i; 7 | char *p; 8 | 9 | printf ("01 02 03 04\n"); 10 | for (i = 1, p = (char*)&n; i <= 4; i++, p++) { 11 | *p = (char)i; 12 | } 13 | printf ("%08X\n", n); 14 | exit(0); 15 | } 16 | -------------------------------------------------------------------------------- /byte_swapping/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | EXES := bs 4 | 5 | include $(TEMPLATES)/c.mk 6 | 7 | -------------------------------------------------------------------------------- /catlock/catlock.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | static void Close (int fd) { 12 | if (fd != 0) (void) close (fd); 13 | } 14 | 15 | #define BLK_SZ 1024 16 | 17 | int main (int argc, char *argv[]) { 18 | 19 | char *me = basename (argv[0]); 20 | int sfd, dfd; 21 | int res; 22 | off_t offset; 23 | size_t rsize, wsize; 24 | char buffer[BLK_SZ]; 25 | char *ifm, *ofm; 26 | 27 | /* 1 arg : dest file */ 28 | /* 2 args: source file, dest file */ 29 | if (argc == 2) { 30 | ifm = NULL; 31 | ofm = argv[1]; 32 | } else if (argc == 3) { 33 | ifm = argv[1]; 34 | ofm = argv[2]; 35 | } else { 36 | fprintf (stderr, "Usage: %s [ ] \n", me); 37 | exit (1); 38 | } 39 | 40 | /* Open source file for reading */ 41 | if ( (ifm == NULL) || (strcmp (ifm, "-") == 0) ) { 42 | sfd = 0; 43 | } else { 44 | for (;;) { 45 | sfd = open (ifm, O_RDONLY, 0); 46 | if ( (sfd >= 0) || (errno != EINTR) ) break; 47 | } 48 | if (sfd < 0) { 49 | fprintf (stderr, "%s: Cannot open file %s for reading -> %s\n", 50 | me, ifm, strerror(errno)); 51 | exit (2); 52 | } 53 | } 54 | 55 | /* Open dest file for writting (not append, cause we need to lock */ 56 | for (;;) { 57 | dfd = open (ofm, O_RDWR, 0); 58 | if ( (dfd >= 0) || (errno != EINTR) ) break; 59 | } 60 | if (dfd < 0) { 61 | fprintf (stderr, "%s: Cannot open file %s for writting -> %s\n", 62 | me, ofm, strerror(errno)); 63 | Close (sfd); 64 | exit (3); 65 | } 66 | 67 | /* Lock dest file */ 68 | for (;;) { 69 | res = lockf (dfd, F_LOCK, 0); 70 | if ( (res != 0) || (errno != EINTR) ) break; 71 | } 72 | if (res != 0) { 73 | fprintf (stderr, "%s: Cannot lock file %s for appending -> %s\n", 74 | me, ofm, strerror(errno)); 75 | (void) Close (sfd); 76 | (void) close (dfd); 77 | exit (3); 78 | } 79 | 80 | /* Prepare dest for append */ 81 | for (;;) { 82 | offset = lseek (dfd, 0, SEEK_END); 83 | if ( (offset != (off_t) -1) || (errno != EINTR) ) break; 84 | } 85 | if (offset == (off_t) -1) { 86 | fprintf (stderr, "%s: Cannot seek file %s for appending -> %s\n", 87 | me, ofm, strerror(errno)); 88 | (void) Close (sfd); 89 | (void) close (dfd); 90 | exit (3); 91 | } 92 | 93 | /* Copy */ 94 | for (;;) { 95 | 96 | /* Read */ 97 | for (;;) { 98 | rsize = read (sfd, buffer, BLK_SZ); 99 | if ( (rsize != (size_t) -1) || (errno != EINTR) ) break; 100 | } 101 | if (rsize == (size_t) -1) { 102 | fprintf (stderr, "%s: Cannot read from file %s -> %s\n", 103 | me, ifm, strerror(errno)); 104 | (void) Close (sfd); 105 | (void) close (dfd); 106 | exit (2); 107 | } 108 | 109 | /* Write */ 110 | for (;;) { 111 | wsize = write (dfd, buffer, rsize); 112 | if ( (wsize != (size_t) -1) || (errno != EINTR) ) break; 113 | } 114 | if (wsize != rsize) { 115 | fprintf (stderr, "%s: Cannot write to file %s -> %s\n", 116 | me, ofm, strerror(errno)); 117 | (void) Close (sfd); 118 | (void) close (dfd); 119 | exit (3); 120 | } 121 | 122 | /* Done when full block could not be read */ 123 | if (rsize != BLK_SZ) { 124 | break; 125 | } 126 | } 127 | 128 | 129 | /* Rewind and unlock if possible */ 130 | offset = lseek (dfd, 0, SEEK_SET); 131 | if (offset != (off_t) -1) { 132 | (void) lockf (dfd, F_ULOCK, 0); 133 | } 134 | 135 | /* Close */ 136 | (void) Close (sfd); 137 | (void) close (dfd); 138 | 139 | /* Done */ 140 | exit (0); 141 | 142 | } 143 | 144 | -------------------------------------------------------------------------------- /catlock/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | EXES := catlock 4 | 5 | include $(TEMPLATES)/c.mk 6 | 7 | -------------------------------------------------------------------------------- /cirtail/circul.h: -------------------------------------------------------------------------------- 1 | #ifndef __CIRCUL_H 2 | #define __CIRCUL_H 3 | 4 | #include 5 | 6 | /* The circulat file descriptor */ 7 | struct cir_file; 8 | 9 | /* The character marker of the circular limit end/start */ 10 | extern char CIR_EOF; 11 | 12 | /* This routine attemps to open a \a size byte circular file \a 13 | * filename. The \a mode parameter is the same as in \c fopen(3). 14 | * \return a pointer to an allocated \c cir_file structure or NULL if an error 15 | * occured. 16 | * \warning This routine performs dynamic memory allocation : don't forget to 17 | * call \c cir_close when finished. 18 | */ 19 | extern struct cir_file* cir_open(const char* filename, const char* mode, 20 | unsigned int size); 21 | 22 | /* This routine closes the circular file \a fd and free the \c cir_file 23 | * structure. 24 | * \return 0 or -1 if an error occured. 25 | */ 26 | extern int cir_close(struct cir_file* fd); 27 | 28 | /* This routine attempts to write to the circular file \a fd, much like 29 | * the write(2) system call. 30 | * \return the number of written bytes or -1 if an error occured. 31 | */ 32 | extern int cir_write(struct cir_file* fd, char* buffer, unsigned int size); 33 | 34 | /* This routine attempts to read from the circular file \a fd, much like 35 | * the read(2) system call. 36 | * \return the number of read bytes or -1 if an error occured. 37 | */ 38 | extern int cir_read(struct cir_file* fd, char* buffer, unsigned int size); 39 | 40 | /* This routine attempts to read a string from the circular file \a fd, 41 | * much like the gets(3) standard C library call. 42 | * \return the length of the read string or -1 if an error occured. 43 | */ 44 | extern int cir_gets(struct cir_file* fd, char* buffer, unsigned int size); 45 | 46 | #endif 47 | 48 | -------------------------------------------------------------------------------- /cirtail/cirpipe.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | /* Read stdin (a pipe) flow and outputs it in a circular file (argv[1]) */ 12 | /* of a given size (arv[2]) */ 13 | 14 | #include "circul.h" 15 | 16 | #define INTERNAL_BUFFER_SIZE 1024 17 | char buffer[INTERNAL_BUFFER_SIZE]; 18 | 19 | 20 | int main (int argc, char *argv[]) { 21 | 22 | unsigned int size; 23 | int nb_read; 24 | struct cir_file *circul_fd = NULL; 25 | 26 | if (argc < 2) { 27 | fprintf (stderr, "Syntax error. Syntax %s " 28 | " \n", argv[0]); 29 | exit (1); 30 | } 31 | 32 | size = strtol (argv[2], NULL, 10); 33 | if ( (size == 0) || (errno != 0) ) { 34 | fprintf (stderr, "Invalid size %s\n", argv[2]); 35 | exit (1); 36 | } 37 | 38 | /* Open output circular file */ 39 | circul_fd = cir_open(argv[1], "w+", size); 40 | if (circul_fd == NULL) { 41 | fprintf(stderr, "Cannot open the circular file %s\n", argv[1]); 42 | exit (1); 43 | } 44 | 45 | /* Read stdin and write circ */ 46 | for (;;) { 47 | nb_read = read (0, buffer, sizeof(buffer)); 48 | if (nb_read > 0) { 49 | if (cir_write (circul_fd, buffer, nb_read) == -1 ) { 50 | fprintf(stderr, "Failed to write in the circular file\n"); 51 | (void) cir_close (circul_fd); 52 | exit (1); 53 | } 54 | } else if (nb_read < 0) { 55 | perror ("read"); 56 | exit (1); 57 | } else { 58 | /* End of input */ 59 | break; 60 | } 61 | } 62 | 63 | /* Close */ 64 | if (cir_close (circul_fd) == -1) { 65 | fprintf(stderr, "Failed to close the circular file\n"); 66 | exit (1); 67 | } 68 | 69 | /* Done */ 70 | exit (0); 71 | 72 | } 73 | 74 | 75 | -------------------------------------------------------------------------------- /cirtail/cirtail.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | /* Tail -f a circular file (argv[1]), outputs on stdout */ 9 | /* option -i changes the polling period (default 1000 ms) */ 10 | 11 | #include "circul.h" 12 | 13 | #define DEFAULT_DELAY_MS 1000 14 | 15 | #define BUFFER_SIZE 512 16 | 17 | int main (int argc, char *argv[]) { 18 | 19 | int c; 20 | FILE * circul_file; 21 | int delay_ms; 22 | char * circular_file_name; 23 | struct timeval delay; 24 | long last_pos; 25 | char buffer [BUFFER_SIZE]; 26 | int len; 27 | long nb_block; 28 | int offset; 29 | 30 | circular_file_name = NULL; 31 | delay_ms = DEFAULT_DELAY_MS; 32 | if (argc == 2) { 33 | delay_ms = DEFAULT_DELAY_MS; 34 | circular_file_name = argv[1]; 35 | } else { 36 | if ( (argc == 4) && (strcmp(argv[1], "-i") == 0) ) { 37 | delay_ms = atoi (argv[2]); 38 | if (delay_ms > 0) { 39 | circular_file_name = argv[3]; 40 | } 41 | } 42 | } 43 | 44 | if (circular_file_name == NULL) { 45 | fprintf (stderr, "Syntax error. Syntax %s " 46 | "[ -i ] \n", argv[0]); 47 | exit (1); 48 | } 49 | 50 | /* Open linear file */ 51 | circul_file = fopen(circular_file_name, "r"); 52 | if (circul_file == (FILE*) NULL) { 53 | perror ("fopen"); 54 | fprintf(stderr, "Cannot open the circular file %s\n", 55 | circular_file_name); 56 | exit (1); 57 | } 58 | 59 | /* Locate mark */ 60 | /* Look first end of file */ 61 | (void) fseek(circul_file, -1, SEEK_END); 62 | c = getc(circul_file); 63 | 64 | if (c != CIR_EOF) { 65 | /* Look for the mark from beginning */ 66 | (void) fseek(circul_file, 0, SEEK_SET); 67 | c = '\0'; 68 | nb_block = 1; 69 | do { 70 | len = fread (buffer, 1, BUFFER_SIZE, circul_file); 71 | if (len == 0) { 72 | /* Mark has moved back at the beginning during our search */ 73 | /* Give up the search and let's go to standard behaviour */ 74 | nb_block = 1; 75 | offset = 0; 76 | c = CIR_EOF; 77 | } else { 78 | for (offset = 0; offset < len; offset++) { 79 | if (buffer[offset] == CIR_EOF) { 80 | c = CIR_EOF; 81 | break; 82 | } 83 | } 84 | nb_block ++; 85 | } 86 | } while (c != CIR_EOF); 87 | (void) fseek(circul_file, offset - len, SEEK_CUR); 88 | } else { 89 | /* Mark is at end of file */ 90 | fseek (circul_file, -1, SEEK_CUR); 91 | nb_block = -1; 92 | } 93 | 94 | /* Mark is found */ 95 | /* Go back one block to have something to display */ 96 | if (nb_block == 1) { 97 | (void) fseek(circul_file, 0, SEEK_SET); 98 | } else { 99 | (void) fseek(circul_file, -BUFFER_SIZE, SEEK_CUR); 100 | } 101 | 102 | for (;;) { 103 | c = getc(circul_file); 104 | 105 | if ( (c != CIR_EOF) && (c != EOF) ) { 106 | /* Normal behaviour */ 107 | (void) putchar (c); 108 | } else { 109 | if (c == EOF) { 110 | /* End of file. Look for mark from beginning of file */ 111 | last_pos = 0; 112 | fclose (circul_file); 113 | } else { 114 | /* Mark found. Current end of file */ 115 | /* Close file, wait a bit, then look for mark from */ 116 | /* same location */ 117 | last_pos = ftell (circul_file) - 1; 118 | fclose (circul_file); 119 | (void) fflush (stdout); 120 | delay.tv_sec = delay_ms / 1000; 121 | delay.tv_usec = (delay_ms % 1000) * 1000; 122 | (void) select (0, (fd_set *) NULL, (fd_set *) NULL, 123 | (fd_set *) NULL, &delay); 124 | } 125 | circul_file = fopen(circular_file_name, "r"); 126 | if (circul_file == (FILE*) NULL) { 127 | perror ("fopen"); 128 | fprintf(stderr, "Cannot re-open the circular file %s\n", 129 | circular_file_name); 130 | break; 131 | } 132 | (void) fseek(circul_file, last_pos, SEEK_SET); 133 | } 134 | } 135 | exit(1); 136 | } 137 | 138 | -------------------------------------------------------------------------------- /cirtail/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | LIBS := libcircul 4 | OBJS_libcircul := circul 5 | 6 | EXES := cirtail uncircular cirpipe 7 | LIBS_cirtail := libcircul 8 | LARGS_cirtail := -lm 9 | LIBS_uncircular := libcircul 10 | LARGS_uncircular := -lm 11 | LIBS_cirpipe := libcircul 12 | LARGS_cirpipe := -lm 13 | 14 | include $(TEMPLATES)/c.mk 15 | 16 | -------------------------------------------------------------------------------- /cirtail/uncircular.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | /* Uncircular and concat several circular files into stdout */ 12 | 13 | #include "circul.h" 14 | 15 | #define INTERNAL_BUFFER_SIZE 512 16 | char buffer[INTERNAL_BUFFER_SIZE]; 17 | 18 | static int uncircular_one (char *input_file_name) { 19 | 20 | size_t char_read; 21 | struct cir_file *circul_fd = NULL; 22 | 23 | /* Generate linear file */ 24 | circul_fd = cir_open(input_file_name, "r", 0); 25 | if (circul_fd == NULL) { 26 | fprintf(stderr, "Cannot open the circular file %s\n", input_file_name); 27 | return (1); 28 | } 29 | 30 | do { 31 | char_read = 0; 32 | char_read = cir_read(circul_fd, buffer, INTERNAL_BUFFER_SIZE); 33 | if ((int) char_read == -1) { 34 | fprintf(stderr, "Cannot read on circular file %s\n", input_file_name); 35 | return (1); 36 | } 37 | 38 | if (fwrite(buffer, 1, char_read, stdout) != char_read) { 39 | fprintf(stderr, "Cannot write (%ld bytes) on stdout\n", char_read); 40 | return (1); 41 | } 42 | } while ( (char_read != 0) && ((int) char_read != -1)); 43 | 44 | cir_close (circul_fd); 45 | circul_fd = NULL; 46 | return (0); 47 | } 48 | 49 | int main (int argc, char *argv[]) { 50 | int result; 51 | int i; 52 | 53 | 54 | if (argc < 2) { 55 | fprintf (stderr, "Syntax error. Syntax %s { }\n", 56 | argv[0]); 57 | exit (1); 58 | } 59 | 60 | /* Process each argument */ 61 | result = 0; 62 | for (i = 1; i < argc; i++) { 63 | result += uncircular_one(argv[i]); 64 | } 65 | 66 | if (fwrite("\n", 1, 1, stdout) != 1) { 67 | fprintf(stderr, "Cannot write last \\n on stdout\n"); 68 | exit (1); 69 | } 70 | 71 | exit (result != 0); 72 | } 73 | 74 | 75 | -------------------------------------------------------------------------------- /delay/delay.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "boolean.h" 7 | #include "timeval.h" 8 | 9 | extern char *basename (const char *filename); 10 | 11 | int main(int argc, char *argv[]) { 12 | 13 | timeout_t timeout; 14 | int i, j; 15 | 16 | timeout.tv_sec = 0; 17 | timeout.tv_usec = 0; 18 | 19 | if (argc == 1) { 20 | exit (0); 21 | } else if (argc > 3) { 22 | fprintf (stderr, "Syntax Error. Usage : %s [secs [msecs]]\n", basename(argv[0])); 23 | exit (1); 24 | } else { 25 | for (i = 1; i < argc; i++) { 26 | for (j = 0; (unsigned int)j < strlen(argv[i]); j++) { 27 | if (! isdigit((int)argv[i][j])) { 28 | fprintf (stderr, "Syntax Error. Usage : %s [secs [msecs]]\n", basename(argv[0])); 29 | exit (1); 30 | } 31 | } 32 | } 33 | } 34 | 35 | 36 | timeout.tv_sec = atoi(argv[1]); 37 | 38 | if (argc == 3) timeout.tv_usec = atoi(argv[2]) * 1000; 39 | 40 | delay(&timeout); 41 | 42 | exit (0); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /delay/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DINCL := boolean 4 | DLIBA := timeval 5 | 6 | EXES := delay 7 | 8 | include $(TEMPLATES)/c.mk 9 | 10 | -------------------------------------------------------------------------------- /delta_time/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DINCL := boolean 4 | DLIBA := timeval socket_evt mutex wait_evt dynlist 5 | 6 | EXES := delta_time 7 | 8 | include $(TEMPLATES)/c.mk 9 | 10 | -------------------------------------------------------------------------------- /dos2unix/dos2unix.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "boolean.h" 8 | 9 | #define SUFFIX ".tmp" 10 | 11 | #define write_char(c) {if (putc((int)c, fo) == EOF) { \ 12 | perror ("putc"); \ 13 | fprintf (stderr, "Error writting on %s\n", file_name); \ 14 | break; \ 15 | } \ 16 | } 17 | 18 | static void convert (char *file_name) { 19 | char *unix_file_name; 20 | FILE *fi, *fo; 21 | int c; 22 | char c1; 23 | 24 | unix_file_name = malloc(strlen(file_name) + sizeof(SUFFIX)); 25 | if (unix_file_name == (char*) NULL) { 26 | perror ("malloc"); 27 | fprintf (stderr, "Error allocating file name %s%s\n", file_name, SUFFIX); 28 | return; 29 | } 30 | strcpy (unix_file_name, file_name); 31 | strcat (unix_file_name, ".tmp"); 32 | 33 | 34 | if ( (fi = fopen (file_name, "rb")) == (FILE*)NULL) { 35 | perror ("fopen"); 36 | fprintf (stderr, "Error openning %s for reading\n", file_name); 37 | free (unix_file_name); 38 | return; 39 | } 40 | 41 | if ( (fo = fopen (unix_file_name, "wb")) == (FILE*)NULL) { 42 | perror ("fopen"); 43 | fprintf (stderr, "Error openning %s for writting\n", unix_file_name); 44 | (void) fclose(fi); 45 | free (unix_file_name); 46 | return; 47 | } 48 | 49 | /* 0D 0A --> 0A */ 50 | /* 1A --> Close */ 51 | for (;;) { 52 | c = getc(fi); 53 | if (c == (char) 0x0D) { 54 | c1 = getc(fi); 55 | if (c1 != (char) 0x0A) { 56 | write_char(c); 57 | } 58 | write_char(c1); 59 | } else if ( (c == 0x1A) || (c == EOF) ) { 60 | break; 61 | } else { 62 | write_char(c); 63 | } 64 | } 65 | 66 | if (fclose(fi) != 0) { 67 | perror ("fclose"); 68 | fprintf (stderr, "Error closing %s after processing\n", file_name); 69 | } 70 | 71 | if (fclose(fo) != 0) { 72 | perror ("fclose"); 73 | fprintf (stderr, "Error closing %s after processing\n", unix_file_name); 74 | } 75 | 76 | if (unlink (file_name) == -1) { 77 | perror ("unlink"); 78 | fprintf (stderr, "Error removing %s after processing\n", 79 | file_name); 80 | free (unix_file_name); 81 | return; 82 | } 83 | if (rename (unix_file_name, file_name) == -1) { 84 | perror ("rename"); 85 | fprintf (stderr, "Error renaming %s to %s after processing\n", 86 | unix_file_name, file_name); 87 | free (unix_file_name); 88 | exit (1); 89 | } 90 | free (unix_file_name); 91 | 92 | } 93 | 94 | int main (int argc, char *argv[]) { 95 | 96 | 97 | int cur_arg; 98 | 99 | for (cur_arg=2; cur_arg <= argc; cur_arg++) { 100 | printf ("Converting dos to unix : %s\n", argv[cur_arg-1]); 101 | convert(argv[cur_arg-1]); 102 | } 103 | printf ("Done.\n"); 104 | exit (0); 105 | } 106 | 107 | -------------------------------------------------------------------------------- /dos2unix/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DINCL := boolean 4 | 5 | EXES := dos2unix unix2dos 6 | 7 | include $(TEMPLATES)/c.mk 8 | 9 | -------------------------------------------------------------------------------- /dos2unix/unix2dos.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "boolean.h" 8 | 9 | #define SUFFIX ".tmp" 10 | 11 | #define write_char(c) {if (putc((int)c, fo) == EOF) { \ 12 | perror ("putc"); \ 13 | fprintf (stderr, "Error writting on %s\n", file_name); \ 14 | break; \ 15 | } \ 16 | } 17 | 18 | static void convert (char *file_name) { 19 | char *dos_file_name; 20 | FILE *fi, *fo; 21 | char c; 22 | 23 | dos_file_name = malloc(strlen(file_name) + sizeof(SUFFIX)); 24 | if (dos_file_name == (char*) NULL) { 25 | perror ("malloc"); 26 | fprintf (stderr, "Error allocating file name %s%s\n", file_name, SUFFIX); 27 | return; 28 | } 29 | strcpy (dos_file_name, file_name); 30 | strcat (dos_file_name, ".tmp"); 31 | 32 | if ( (fi = fopen (file_name, "rb")) == (FILE*)NULL) { 33 | perror ("fopen"); 34 | fprintf (stderr, "Error openning %s for reading\n", file_name); 35 | free (dos_file_name); 36 | return; 37 | } 38 | 39 | if ( (fo = fopen (dos_file_name, "wb")) == (FILE*)NULL) { 40 | perror ("fopen"); 41 | fprintf (stderr, "Error openning %s for writting\n", dos_file_name); 42 | (void) fclose(fi); 43 | free (dos_file_name); 44 | return; 45 | } 46 | 47 | /* 0A --> 0D 0A */ 48 | /* EOF --> 1A Close */ 49 | for (;;) { 50 | c = getc(fi); 51 | if (c == (char) 0x0A) { 52 | write_char(0X0D); 53 | write_char(c); 54 | } else if (c == (char) EOF) { 55 | write_char(0x1A); 56 | break; 57 | } else { 58 | write_char(c); 59 | } 60 | } 61 | 62 | if (fclose(fi) != 0) { 63 | perror ("fclose"); 64 | fprintf (stderr, "Error closing %s after processing\n", file_name); 65 | free (dos_file_name); 66 | } 67 | 68 | if (fclose(fo) != 0) { 69 | perror ("fclose"); 70 | fprintf (stderr, "Error closing %s after processing\n", dos_file_name); 71 | free (dos_file_name); 72 | } 73 | 74 | if (unlink (file_name) == -1) { 75 | perror ("unlink"); 76 | fprintf (stderr, "Error removing %s after processing\n", 77 | file_name); 78 | free (dos_file_name); 79 | return; 80 | } 81 | if (rename (dos_file_name, file_name) == -1) { 82 | perror ("rename"); 83 | fprintf (stderr, "Error renaming %s to %s after processing\n", 84 | dos_file_name, file_name); 85 | free (dos_file_name); 86 | return; 87 | } 88 | 89 | free (dos_file_name); 90 | } 91 | 92 | int main (int argc, char *argv[]) { 93 | 94 | 95 | int cur_arg; 96 | 97 | for (cur_arg=2; cur_arg <= argc; cur_arg++) { 98 | printf ("Converting unix to dos : %s\n", argv[cur_arg-1]); 99 | convert(argv[cur_arg-1]); 100 | } 101 | printf ("Done.\n"); 102 | exit (0); 103 | } 104 | 105 | -------------------------------------------------------------------------------- /dt/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | EXES := settime dt 4 | 5 | include $(TEMPLATES)/c.mk 6 | 7 | -------------------------------------------------------------------------------- /dt/settime.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | static void error(void) __attribute__ ((noreturn)); 10 | static void error(void) { 11 | fprintf (stderr, "Usage: settime Dd/Mm/YYyy hh:mm:ss [ms]\n"); 12 | exit (1); 13 | } 14 | 15 | int main (int argc, char *argv[]) { 16 | struct tm tms; 17 | struct timeval tv; 18 | char a1[11]; 19 | int l1; 20 | char a2[9]; 21 | int l2; 22 | char *p, *pp; 23 | 24 | /* DD/MM/YYYY hh:mm:ss [ms] */ 25 | if ((argc != 3) && (argc != 4) ) error(); 26 | l1 = strlen(argv[1]); 27 | l2 = strlen(argv[2]); 28 | if (l1 != 10) error(); 29 | if (l2 != 8) error(); 30 | 31 | strcpy (a1, argv[1]); 32 | strcpy (a2, argv[2]); 33 | 34 | /* Parse a1 */ 35 | pp = argv[1]; 36 | p = strchr(pp, '/'); 37 | if (p == NULL) error(); 38 | *p = '\0'; 39 | if (strlen(pp) != 2) error(); 40 | tms.tm_mday = atoi(pp); 41 | if ( (tms.tm_mday < 1) || (tms.tm_mday > 31) ) error(); 42 | 43 | pp = p + 1; 44 | p = strchr(pp, '/'); 45 | if (p == NULL) error(); 46 | *p = '\0'; 47 | if (strlen(pp) != 2) error(); 48 | tms.tm_mon = atoi(pp) - 1; 49 | if ( (tms.tm_mon < 0) || (tms.tm_mon > 11) ) error(); 50 | 51 | pp = p + 1; 52 | p = strchr(pp, '/'); 53 | if (p != NULL) error(); 54 | if (strlen(pp) != 4) error(); 55 | tms.tm_year = atoi(pp) - 1900; 56 | if (tms.tm_year < 0) error(); 57 | 58 | 59 | 60 | /* Parse a2 */ 61 | pp = argv[2]; 62 | p = strchr(pp, ':'); 63 | if (p == NULL) error(); 64 | *p = '\0'; 65 | if (strlen(pp) != 2) error(); 66 | tms.tm_hour = atoi(pp); 67 | if ( (tms.tm_hour < 0) || (tms.tm_hour > 23) ) error(); 68 | 69 | pp = p + 1; 70 | p = strchr(pp, ':'); 71 | if (p == NULL) error(); 72 | *p = '\0'; 73 | if (strlen(pp) != 2) error(); 74 | tms.tm_min = atoi(pp); 75 | if ( (tms.tm_min < 0) || (tms.tm_min > 59) ) error(); 76 | 77 | pp = p + 1; 78 | p = strchr(pp, ':'); 79 | if (p != NULL) error(); 80 | if (strlen(pp) != 2) error(); 81 | tms.tm_sec = atoi(pp); 82 | if ( (tms.tm_sec < 0) || (tms.tm_sec > 59) ) error(); 83 | 84 | /* Make tv_secs */ 85 | tv.tv_sec = mktime(&tms); 86 | if (tv.tv_sec == -1) { 87 | perror("mktime"); 88 | error(); 89 | } 90 | 91 | /* make tv_usecs */ 92 | if (argc == 4) { 93 | tv.tv_usec = atoi(argv[3]); 94 | } else { 95 | tv.tv_usec = 0; 96 | } 97 | if ( (tv.tv_usec < 0) || (tv.tv_usec >= 1000) ) error(); 98 | tv.tv_usec = tv.tv_usec * 1000; 99 | 100 | printf ("%ld secs %ld usecs.\n", tv.tv_sec, tv.tv_usec); 101 | 102 | /* Set time */ 103 | if (settimeofday(&tv, NULL) == 0) { 104 | printf ("Done\n"); 105 | exit(0); 106 | } else { 107 | perror("settimeofday"); 108 | error(); 109 | } 110 | } 111 | 112 | -------------------------------------------------------------------------------- /dynlist/dynlist.h: -------------------------------------------------------------------------------- 1 | #ifndef DYNLIST_H 2 | #define DYNLIST_H 3 | 4 | #include "boolean.h" 5 | 6 | /* The list (ADT) */ 7 | typedef struct dlist dlist; 8 | 9 | /* Initialise a list */ 10 | extern void dlist_init (dlist *list, unsigned int data_size); 11 | 12 | /* NAVIGATION */ 13 | /* Is list empty */ 14 | extern boolean dlist_is_empty (const dlist *list); 15 | /* List length is 0 or pos_from_first + pos_from_last - 1) */ 16 | extern unsigned int dlist_length (const dlist *list); 17 | /* Position in list, from start or from end */ 18 | /* 0 when list is empty */ 19 | /* List length is 0 or pos_from_first + pos_from_last - 1) */ 20 | extern unsigned int dlist_get_pos (const dlist *list, boolean from_first); 21 | /* Move at beginning or end */ 22 | extern void dlist_rewind (dlist *list, boolean at_first); 23 | /* Move one cell forward or backward (if possible) */ 24 | extern void dlist_move (dlist *list, boolean forward); 25 | 26 | /* READ / INSERT / DELETE */ 27 | /* Read current (copy from list) */ 28 | extern void dlist_read (const dlist *list, void * data); 29 | /* Replace current */ 30 | extern void dlist_replace (const dlist *list, void * data); 31 | /* Insert after or before current (copy to list and become current) */ 32 | extern void dlist_insert (dlist *list, const void * data, boolean after_curr); 33 | /* Delete current. Move to next or prev */ 34 | extern void dlist_delete (dlist *list, boolean forward); 35 | /* Delete the whole list (re-inits) */ 36 | extern void dlist_delete_all (dlist *list); 37 | 38 | /* SORT */ 39 | /* Type of function that compares 2 data. */ 40 | /* Must be strict: less_than (p, p) -> FALSE */ 41 | typedef boolean less_than_func (const void *, const void*); 42 | /* Quick sort the list according to less_than function and rewind */ 43 | extern void dlist_sort (dlist *list, less_than_func *less_than); 44 | 45 | /* Private */ 46 | struct cell; 47 | 48 | typedef struct cell { 49 | struct cell * prev; 50 | struct cell * next; 51 | void * data; 52 | } cell; 53 | 54 | struct dlist { 55 | cell * first; 56 | cell * last; 57 | cell * curr; 58 | unsigned int pos_first; 59 | unsigned int pos_last; 60 | unsigned int data_size; 61 | }; 62 | 63 | #endif 64 | 65 | -------------------------------------------------------------------------------- /dynlist/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DINCL := boolean 4 | 5 | EXES := tdl 6 | LIBS := libdynlist 7 | 8 | OBJS_libdynlist := dynlist 9 | 10 | LIBS_tdl := libdynlist 11 | 12 | include $(TEMPLATES)/c.mk 13 | 14 | -------------------------------------------------------------------------------- /dynlist/tdl.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "dynlist.h" 5 | 6 | static boolean less_than (const void *l, const void *r) { 7 | return (*(const int*)l < *(const int*)r); 8 | } 9 | 10 | int main (void) { 11 | 12 | dlist list; 13 | int i, v; 14 | 15 | dlist_init (&list, sizeof(int)); 16 | 17 | printf ("Add 10 elements\n"); 18 | for (i = 1; i <= 10; i++) { 19 | dlist_insert (&list, &i, TRUE); 20 | } 21 | 22 | printf ("Reads 5 elements from the last one:"); 23 | dlist_rewind (&list, FALSE); 24 | for (i = 1; i <= 5; i++) { 25 | dlist_read (&list, &v); 26 | printf (" %02d", v); 27 | dlist_move (&list, FALSE); 28 | } 29 | printf ("\n"); 30 | 31 | printf ("List length: %02d\n", dlist_length (&list)); 32 | 33 | printf ("Deletes the current\n"); 34 | dlist_delete (&list, TRUE); 35 | 36 | printf ("Pos from first: %02d List length: %02d\n", 37 | dlist_get_pos (&list, TRUE), dlist_length (&list)); 38 | 39 | printf ("Reads 7 elements from the first one:"); 40 | dlist_rewind (&list, TRUE); 41 | for (i = 1; i <= 7; i++) { 42 | dlist_read (&list, &v); 43 | printf (" %02d", v); 44 | dlist_move (&list, TRUE); 45 | } 46 | printf ("\n"); 47 | 48 | printf ("Adds the element 50 before current position and read: "); 49 | v = 50; 50 | dlist_insert (&list, &v, FALSE); 51 | dlist_read (&list, &v); 52 | printf ("%02d\n", v); 53 | 54 | printf ("List length: %02d\n", dlist_length (&list)); 55 | printf ("Reads all elements from the first one:"); 56 | dlist_rewind (&list, TRUE); 57 | for (;;) { 58 | dlist_read (&list, &v); 59 | printf (" %02d", v); 60 | if (dlist_get_pos (&list, FALSE) == 1) break; 61 | dlist_move (&list, TRUE); 62 | } 63 | printf ("\n"); 64 | 65 | printf ("Sort: "); 66 | dlist_sort (&list, less_than); 67 | for (;;) { 68 | dlist_read (&list, &v); 69 | printf (" %02d", v); 70 | if (dlist_get_pos (&list, FALSE) == 1) break; 71 | dlist_move (&list, TRUE); 72 | } 73 | printf ("\n"); 74 | 75 | printf ("Delete all\n"); 76 | dlist_delete_all (&list); 77 | printf ("List length: %02d\n", dlist_length (&list)); 78 | 79 | exit (0); 80 | } 81 | 82 | -------------------------------------------------------------------------------- /enquire/float.h: -------------------------------------------------------------------------------- 1 | /* float.h */ 2 | /* Produced by enquire version 5.0, CWI, Amsterdam */ 3 | 4 | /* Radix of exponent representation */ 5 | #define FLT_RADIX 2 6 | /* Number of base-FLT_RADIX digits in the significand of a float */ 7 | #define FLT_MANT_DIG 24 8 | /* Number of decimal digits of precision in a float */ 9 | #define FLT_DIG 6 10 | /* Addition rounds to 0: zero, 1: nearest, 2: +inf, 3: -inf, -1: unknown */ 11 | #define FLT_ROUNDS 1 12 | /* Difference between 1.0 and the minimum float greater than 1.0 */ 13 | #define FLT_EPSILON 1.19209290e-07F 14 | /* Minimum int x such that FLT_RADIX**(x-1) is a normalised float */ 15 | #define FLT_MIN_EXP (-125) 16 | /* Minimum normalised float */ 17 | #define FLT_MIN 1.17549435e-38F 18 | /* Minimum int x such that 10**x is a normalised float */ 19 | #define FLT_MIN_10_EXP (-37) 20 | /* Maximum int x such that FLT_RADIX**(x-1) is a representable float */ 21 | #define FLT_MAX_EXP 128 22 | /* Maximum float */ 23 | #define FLT_MAX 3.40282347e+38F 24 | /* Maximum int x such that 10**x is a representable float */ 25 | #define FLT_MAX_10_EXP 38 26 | 27 | /* Number of base-FLT_RADIX digits in the significand of a double */ 28 | #define DBL_MANT_DIG 53 29 | /* Number of decimal digits of precision in a double */ 30 | #define DBL_DIG 15 31 | /* Difference between 1.0 and the minimum double greater than 1.0 */ 32 | #define DBL_EPSILON 2.2204460492503131e-16 33 | /* Minimum int x such that FLT_RADIX**(x-1) is a normalised double */ 34 | #define DBL_MIN_EXP (-1021) 35 | /* Minimum normalised double */ 36 | #define DBL_MIN 2.2250738585072014e-308 37 | /* Minimum int x such that 10**x is a normalised double */ 38 | #define DBL_MIN_10_EXP (-307) 39 | /* Maximum int x such that FLT_RADIX**(x-1) is a representable double */ 40 | #define DBL_MAX_EXP 1024 41 | /* Maximum double */ 42 | #define DBL_MAX 1.7976931348623157e+308 43 | /* Maximum int x such that 10**x is a representable double */ 44 | #define DBL_MAX_10_EXP 308 45 | 46 | /* Number of base-FLT_RADIX digits in the significand of a long double */ 47 | #define LDBL_MANT_DIG 64 48 | /* Number of decimal digits of precision in a long double */ 49 | #define LDBL_DIG 18 50 | /* Difference between 1.0 and the minimum long double greater than 1.0 */ 51 | #define LDBL_EPSILON 1.08420217248550443401e-19L 52 | /* Minimum int x such that FLT_RADIX**(x-1) is a normalised long double */ 53 | #define LDBL_MIN_EXP (-16381) 54 | /* Minimum normalised long double */ 55 | #define LDBL_MIN 3.36210314311209350626e-4932L 56 | /* Minimum int x such that 10**x is a normalised long double */ 57 | #define LDBL_MIN_10_EXP (-4931) 58 | /* Maximum int x such that FLT_RADIX**(x-1) is a representable long double */ 59 | #define LDBL_MAX_EXP 16384 60 | /* Maximum long double */ 61 | #define LDBL_MAX 1.18973149535723176502e+4932L 62 | /* Maximum int x such that 10**x is a representable long double */ 63 | #define LDBL_MAX_10_EXP 4932 64 | 65 | /* *** Something fishy here! 66 | Exponent size + significand size doesn't match with the size of a long double! */ 67 | 68 | 69 | -------------------------------------------------------------------------------- /enquire/limits.h: -------------------------------------------------------------------------------- 1 | /* limits.h */ 2 | /* Produced by enquire version 5.0, CWI, Amsterdam */ 3 | 4 | /* Number of bits in a storage unit */ 5 | #define CHAR_BIT 8 6 | /* Maximum char */ 7 | #define CHAR_MAX 127 8 | /* Minimum char */ 9 | #define CHAR_MIN (-128) 10 | /* Maximum signed char */ 11 | #define SCHAR_MAX 127 12 | /* Minimum signed char */ 13 | #define SCHAR_MIN (-128) 14 | /* Maximum unsigned char (minimum is always 0) */ 15 | #define UCHAR_MAX 255 16 | /* Maximum short */ 17 | #define SHRT_MAX 32767 18 | /* Minimum short */ 19 | #define SHRT_MIN (-32768) 20 | /* Maximum int */ 21 | #define INT_MAX 2147483647 22 | /* Minimum int */ 23 | #define INT_MIN (-2147483647-1) 24 | /* Maximum long */ 25 | #define LONG_MAX 2147483647L 26 | /* Minimum long */ 27 | #define LONG_MIN (-2147483647L-1L) 28 | /* Maximum unsigned short (minimum is always 0) */ 29 | #define USHRT_MAX 65535 30 | /* Maximum unsigned int (minimum is always 0) */ 31 | #define UINT_MAX 4294967295U 32 | /* Maximum unsigned long (minimum is always 0) */ 33 | #define ULONG_MAX 4294967295UL 34 | -------------------------------------------------------------------------------- /enquire/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | EXES := enquire 4 | 5 | CCOPT_Linux := 6 | 7 | include $(TEMPLATES)/c.mk 8 | 9 | -------------------------------------------------------------------------------- /font_size/font_size.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /* Display the height, width and vertical offset of several fonts */ 6 | 7 | char *prog_name; 8 | 9 | static void usage (void) { 10 | printf ("Usage : %s { }\n", prog_name); 11 | } 12 | 13 | static int result; 14 | static void error (const char *msg, int fatal) { 15 | fprintf (stderr, "ERROR: %s.\n", msg); 16 | result = 1; 17 | if (fatal) { 18 | usage(); 19 | exit (result); 20 | } 21 | } 22 | 23 | int main (int argc, char *argv[]) { 24 | /* Error message */ 25 | char msg [1024]; 26 | /* X11 display */ 27 | Display *disp; 28 | /* Index of font argument */ 29 | int i; 30 | /* Font stuff */ 31 | XFontSet font_set; 32 | int missing_count; 33 | char **font_names; 34 | XFontStruct **fonts, *font; 35 | int res; 36 | 37 | /* Check syntax: 2 or more arguments: and ... */ 38 | prog_name = argv[0]; 39 | if (argc < 3) { 40 | error ("Invalid argument", True); 41 | } 42 | 43 | /* Open display */ 44 | disp = XOpenDisplay (argv[1]); 45 | if (disp == NULL) { 46 | sprintf (msg, "Can't open display %s", argv[1]); 47 | error (msg, True); 48 | } 49 | 50 | /* Loop on all font names */ 51 | result = 0; 52 | for (i = 2; i < argc; i++) { 53 | 54 | /* Create font set */ 55 | font_set = XCreateFontSet (disp, argv[i], &font_names, &missing_count, NULL); 56 | if (font_set == NULL) { 57 | sprintf (msg, "Can't create font set of %s", argv[i]); 58 | error (msg, False); 59 | continue; 60 | } 61 | if (missing_count != 0) { 62 | int j; 63 | for (j = 0; j < missing_count; j++) { 64 | printf ("Missing font %s for %s.\n", font_names[j], argv[i]); 65 | } 66 | } 67 | 68 | /* Load font characteristics */ 69 | res = XFontsOfFontSet (font_set, &fonts, &font_names); 70 | if (res == -1) { 71 | sprintf (msg, "Cannot get fonts from set for %s", argv[i]); 72 | error (msg, False); 73 | XFreeFontSet (disp, font_set); 74 | continue; 75 | } 76 | 77 | /* Load font */ 78 | font = XLoadQueryFont (disp, argv[i]); 79 | if (font == NULL) { 80 | sprintf (msg, "Cannot query font %s", argv[i]); 81 | error (msg, False); 82 | XFreeFontSet (disp, font_set); 83 | } 84 | 85 | printf ("Font %s is %dx%d-%d\n", argv[i], 86 | (int)font->max_bounds.width, 87 | (int)(font->ascent + font->descent), 88 | (int)font->ascent); 89 | 90 | /* Done for this font */ 91 | XFreeFontSet (disp, font_set); 92 | XFreeFont (disp, font); 93 | } 94 | 95 | /* Done */ 96 | (void) XCloseDisplay (disp); 97 | exit (result); 98 | 99 | } 100 | 101 | -------------------------------------------------------------------------------- /font_size/list_fonts: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function usage { 4 | echo "Usage: `basename $0` [ ]" 5 | } 6 | 7 | 8 | if [ $# -eq 0 ] ; then 9 | usage 10 | exit 1 11 | fi 12 | export REGEX="$1" 13 | 14 | export NORMAL="" 15 | export BOLD="" 16 | if [ $# -eq 3 ]; then 17 | NORMAL="$2" 18 | BOLD="$3" 19 | elif [ $# -ne 1 ]; then 20 | echo "ERROR: Invalid arguments." 1>&2 21 | usage 22 | exit 1 23 | fi 24 | 25 | # List all matching fonts 26 | export FONTS=`xlsfonts | grep -E "$REGEX"` 27 | 28 | # Size of one font 29 | function size { 30 | local FONT=$1 31 | if [[ "$FONT" =~ ^.*-iso10646-1$ ]] ; then 32 | FONT=`echo $FONT | sed -e "s/-1$/-*/"` 33 | fi 34 | font_size "" "$FONT" 35 | } 36 | 37 | # Size of each font 38 | for FONT in $FONTS ; do 39 | 40 | size $FONT 41 | if [ -n "$NORMAL" ] ; then 42 | BOLD_FONT=`echo $FONT | sed s/$NORMAL/$BOLD/` 43 | size $BOLD_FONT 44 | echo "" 45 | fi 46 | done 47 | 48 | 49 | -------------------------------------------------------------------------------- /font_size/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | EXES := font_size 4 | LARGS_font_size := -lX11 5 | 6 | include $(TEMPLATES)/c.mk 7 | 8 | -------------------------------------------------------------------------------- /forker/forker_messages.h: -------------------------------------------------------------------------------- 1 | #include "boolean.h" 2 | 3 | /****************************************************************************/ 4 | /****** Preliminary definitions ******/ 5 | /****************************************************************************/ 6 | 7 | /* Kind of request and report */ 8 | typedef enum {start_command, kill_command, fexit_command, ping_command} 9 | request_kind_list; 10 | typedef enum {start_report, kill_report, exit_report, fexit_report, 11 | pong_report} report_kind_list; 12 | 13 | /* Request sizing */ 14 | typedef unsigned int command_number; 15 | #define MAX_TEXT_LG 512 /* Program + arguments */ 16 | #define MAX_ENV_LG 256 /* Environment variables */ 17 | #define MAX_DIR_LG 256 /* Current dir/stdout /stderr */ 18 | 19 | /* Start request structure */ 20 | typedef struct { 21 | command_number number; /* Managed by the client */ 22 | char command_text[MAX_TEXT_LG]; /* program\0arg1\0arg2\0 ... argb\0\0 */ 23 | char environ_variables[MAX_ENV_LG]; /* var1=val1\0 ........ varn=valn\0\0 */ 24 | char currend_dir[MAX_DIR_LG]; /* path\0 */ 25 | char output_flow[MAX_DIR_LG]; /* path_to_file\0 */ 26 | unsigned char append_output; /* 0 (create) or 1 (append) */ 27 | char error_flow[MAX_DIR_LG]; /* path_to_file\0 */ 28 | unsigned char append_error; /* 0 (create) or 1 (append) */ 29 | } start_request_t; 30 | 31 | /* Kill request structure */ 32 | typedef struct { 33 | command_number number; /* Managed by the client */ 34 | int signal_number; /* Signal num to send */ 35 | } kill_request_t; 36 | 37 | /* Forker Exit request structure */ 38 | typedef struct { 39 | int exit_code; /* Code to exit with */ 40 | } fexit_request_t; 41 | 42 | /* Request */ 43 | typedef union { 44 | start_request_t start_request; 45 | kill_request_t kill_request; 46 | fexit_request_t fexit_request; 47 | } request_u; 48 | 49 | /* Start report */ 50 | typedef struct { 51 | command_number number; /* Managed by the client */ 52 | int started_pid; /* Pid of Started process or -1 */ 53 | } start_report_t; 54 | 55 | /* Kill report */ 56 | typedef struct { 57 | command_number number; /* Managed by the client */ 58 | int killed_pid; /* Pid of Killed process or -1 */ 59 | } kill_report_t; 60 | 61 | /* Exit report */ 62 | typedef struct { 63 | command_number number; /* Managed by the client */ 64 | int exit_pid; /* Pid of exited command */ 65 | int exit_status; /* Exit status of command */ 66 | } exit_report_t; 67 | 68 | typedef union { 69 | start_report_t start_report; 70 | kill_report_t kill_report; 71 | exit_report_t exit_report; 72 | } report_u; 73 | 74 | /****************************************************************************/ 75 | /****** Interface definitions ******/ 76 | /****************************************************************************/ 77 | /* The interface request message client -> forker */ 78 | typedef struct { 79 | request_kind_list kind; 80 | #define start_req request.start_request 81 | #define kill_req request.kill_request 82 | #define fexit_req request.fexit_request 83 | request_u request; 84 | } request_message_t; 85 | 86 | /* The interface report message forker -> client */ 87 | typedef struct { 88 | report_kind_list kind; 89 | #define start_rep report.start_report 90 | #define kill_rep report.kill_report 91 | #define exit_rep report.exit_report 92 | report_u report; /* Ok/Nok/Exit_code */ 93 | } report_message_t; 94 | 95 | 96 | -------------------------------------------------------------------------------- /forker/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DINCL := boolean 4 | DLIBA := socket mutex get_line 5 | 6 | EXES := forker client 7 | 8 | include $(TEMPLATES)/c.mk 9 | 10 | -------------------------------------------------------------------------------- /formfeed/formfeed.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define LP_NAME "/dev/lp0" 6 | 7 | int main (void) { 8 | const char form_feed = (char) 0x0C; 9 | FILE * lp; 10 | 11 | lp = fopen (LP_NAME, "a"); 12 | if (lp == (FILE*)NULL) { 13 | perror ("fopen"); 14 | fprintf (stderr, "Cannot open stream %s\n", LP_NAME); 15 | exit (1); 16 | } 17 | 18 | (void) fputc ((int)form_feed, lp); 19 | (void) fclose (lp); 20 | exit (0); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /formfeed/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | EXES := formfeed 4 | 5 | include $(TEMPLATES)/c.mk 6 | 7 | -------------------------------------------------------------------------------- /fread_float/flint.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define usage(n) { \ 6 | fprintf (stderr, "Usage : flint [ -d ]\n"); \ 7 | fprintf (stderr, " or : flint [ ]\n"); \ 8 | exit (n); \ 9 | } 10 | 11 | int main (int argc, char *argv[]) { 12 | 13 | double d; 14 | 15 | double *dp = &d; 16 | float *fp = (float*)&d; 17 | unsigned char *bp = (unsigned char *)&d; 18 | int n, i; 19 | unsigned int u; 20 | 21 | 22 | if (argc == 2) { 23 | sscanf (argv[1], "%f", fp); 24 | n = 4; 25 | } else if (argc == 3) { 26 | if (strcmp(argv[2], "-d") != 0) { 27 | usage(1); 28 | } 29 | sscanf (argv[1], "%lf", dp); 30 | n = 8; 31 | } else if ( (argc == 5) || (argc == 9) ) { 32 | n = argc - 1; 33 | for (i = 1; i <= n; i++, bp++) { 34 | sscanf (argv[i], "%x", &u); 35 | *bp = (unsigned char) u; 36 | } 37 | 38 | } else { 39 | usage(1); 40 | } 41 | 42 | if (argc <= 3) { 43 | for (i = 1; i <= n; i++, bp++) { 44 | printf ("%02X ", (int)*bp); 45 | } 46 | printf ("\n"); 47 | } else if (argc == 5) { 48 | printf ("%f\n", *fp); 49 | } else { 50 | printf ("%g\n", *dp); 51 | } 52 | 53 | exit (0); 54 | 55 | } 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /fread_float/fread_float.c: -------------------------------------------------------------------------------- 1 | #include "stdio.h" 2 | #include "stdlib.h" 3 | #include "string.h" 4 | 5 | #define usage(n) { fprintf (stderr, "Usage : fread_float [ ] [ -d ]\n"); \ 6 | exit (n); } 7 | 8 | int main (int argc, char *argv[]) { 9 | int number = 1; 10 | int double_float = 0; 11 | long int offset; 12 | int i; 13 | float f; 14 | double d; 15 | int res; 16 | 17 | FILE *file; 18 | 19 | if (argc == 4) { 20 | if (strcmp(argv[3], "-d") == 0) { 21 | double_float = 1; 22 | } else { 23 | number = atoi(argv[3]); 24 | } 25 | } else if (argc == 5) { 26 | if (strcmp(argv[4], "-d") == 0) { 27 | double_float = 1; 28 | number = atoi(argv[3]); 29 | } else { 30 | usage(1); 31 | } 32 | } else if (argc != 3) { 33 | usage(1); 34 | } 35 | if (number == 0) { 36 | usage(1); 37 | } 38 | offset = atol(argv[2]); 39 | if (offset == 0) { 40 | usage(1); 41 | } 42 | 43 | printf ("Reading %d %s at pos %ld in file %s\n", 44 | number, (double_float ? "double(s)" : "float(s)"), offset, argv[1]); 45 | 46 | file = fopen (argv[1], "r"); 47 | if (file == (FILE*)NULL) { 48 | perror ("fopen"); 49 | fprintf (stderr, "cannot open file %s\n", argv[1]); 50 | usage(2); 51 | } 52 | 53 | if (fseek (file, offset-1, SEEK_SET) == -1) { 54 | perror ("fseek"); 55 | fprintf (stderr, "cannot move at pos %ld in file %s\n", offset, argv[1]); 56 | usage(2); 57 | } 58 | 59 | for (i = 1; i <= number; i++) { 60 | if (double_float) { 61 | res = fread (&d, sizeof(double), 1, file); 62 | } else { 63 | res = fread (&f, sizeof(float), 1, file); 64 | } 65 | if (res != 1) { 66 | perror ("fread"); 67 | fprintf (stderr, "cannot read %d %s at pos %ld in file %s\n", 68 | number, (double_float ? "double(s)" : "float(s)"), offset, argv[1]); 69 | usage(2); 70 | } 71 | 72 | if (double_float) { 73 | printf ("%g\n", d); 74 | } else { 75 | printf ("%f\n", f); 76 | } 77 | } 78 | 79 | exit (0); 80 | 81 | } 82 | -------------------------------------------------------------------------------- /fread_float/fwrite.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | FILE *file; 5 | float f = 21.0; 6 | double d = 22.0; 7 | 8 | file = fopen("toto", "w"); 9 | fwrite (&f, sizeof(float), 1, file); 10 | fwrite (&d, sizeof(double), 1, file); 11 | return 0; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /fread_float/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | EXES := flint fread_float fwrite 4 | 5 | include $(TEMPLATES)/c.mk 6 | 7 | -------------------------------------------------------------------------------- /get_line/get_line.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "get_line.h" 4 | 5 | /* Reads at most len chars from FILE (stdin if FILE=NULL) */ 6 | /* or until EOL (return) is entered. */ 7 | /* The out string is always terminated by "\n\0" */ 8 | /* Returns the strlen of str if OK */ 9 | /* It returns 0 if EOF or error */ 10 | extern unsigned int get_text (FILE *file, char *str, 11 | const unsigned int len) { 12 | unsigned int u; 13 | int i; 14 | char c; 15 | 16 | errno = 0; 17 | 18 | if (len <= 0) return (0); 19 | 20 | 21 | /* Read line */ 22 | u = 0; 23 | do { 24 | if (u >= len - 1) { 25 | /* End of buffer */ 26 | break; 27 | } 28 | /* Read char */ 29 | if (file == (FILE*)NULL) { 30 | i = getchar(); 31 | } else { 32 | i = fgetc(file); 33 | } 34 | c = (char) i; 35 | if (i == EOF) { 36 | /* Error or end of file */ 37 | break; 38 | } else { 39 | str[u] = c; 40 | u++; 41 | } 42 | 43 | } while (c != EOL); 44 | 45 | str[u] = NUL; 46 | return (u); 47 | } 48 | 49 | /* Reads at most len chars from FILE (stdin if FILE=NULL) */ 50 | /* or until Cr (return) is entered. */ 51 | /* The out string is always NUL terminated (Cr removed) */ 52 | /* Returns the strlen of str if OK */ 53 | /* It returns -1 if EOF or error */ 54 | int get_line (FILE *file, char *str, const int len) { 55 | 56 | int i; 57 | char c; 58 | 59 | errno = 0; 60 | 61 | if (len <= 0) return (0); 62 | 63 | str[0] = NUL; 64 | 65 | /* Read line */ 66 | i = -1; 67 | do { 68 | i ++; 69 | if (i >= len - 1) { 70 | /* End of buffer */ 71 | str[i] = NUL; 72 | break; 73 | } 74 | /* Read char */ 75 | if (file == (FILE*)NULL) { 76 | i = getchar(); 77 | } else { 78 | i = fgetc(file); 79 | } 80 | c = (char) i; 81 | if (i == EOF) { 82 | /* Error or end of file */ 83 | return (-1); 84 | } else if (c == EOL) { 85 | /* End of line */ 86 | str[i] = NUL; 87 | } else { 88 | str[i] = c; 89 | } 90 | 91 | } while (str[i] != NUL); 92 | 93 | 94 | return (i); 95 | 96 | } 97 | 98 | -------------------------------------------------------------------------------- /get_line/get_line.h: -------------------------------------------------------------------------------- 1 | #ifndef __GET_LINE__ 2 | #define __GET_LINE__ 3 | 4 | /* INCLUDE FILES */ 5 | /*****************/ 6 | #include 7 | 8 | #define NUL '\0' 9 | #define EOL '\n' 10 | 11 | /* Reads at most len chars from FILE (stdin if FILE=NULL) */ 12 | /* or until EOL (return) is entered. */ 13 | /* The out string is always NUL terminated */ 14 | /* Returns the strlen of str if OK */ 15 | /* It returns -1 if EOF or error */ 16 | extern int get_line (FILE *file, char *str, const int len); 17 | 18 | /* Reads at most len chars from FILE (stdin if FILE=NULL) */ 19 | /* or until EOL (return) is entered. */ 20 | /* The out string is always NUL terminated */ 21 | /* Returns the strlen of str */ 22 | /* Reads characters up to a New_Line (that is appended) */ 23 | /* or up to the end of file. */ 24 | /* So, either the returned string ends with a New_Line and */ 25 | /* another get can be performed, */ 26 | /* Or the string does not end with New_Line (or is empty) and */ 27 | /* the end of file has been reached or an error has occured. */ 28 | extern unsigned int get_text (FILE *file, char *str, 29 | const unsigned int len); 30 | 31 | #endif /* _GET_LINE */ 32 | 33 | -------------------------------------------------------------------------------- /get_line/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | LIBS := libget_line 4 | OBJS_libget_line := get_line 5 | 6 | include $(TEMPLATES)/c.mk 7 | 8 | -------------------------------------------------------------------------------- /gettimeofdays/gettimeofdays.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "boolean.h" 6 | #include "timeval.h" 7 | #include "sem_util.h" 8 | #include "rusage.h" 9 | 10 | static int semid; 11 | 12 | #define NTIMES 21 13 | 14 | static int get_vtime (timeout_t *time) { 15 | t_result r; 16 | 17 | /* Mesure time for decr_sem, gettimeofday, incr_sem */ 18 | r = decr_sem_id (semid, TRUE); 19 | if (r == ERR) { 20 | perror ("decr_sem_id"); 21 | return 1; 22 | } 23 | get_time (time); 24 | r = incr_sem_id (semid, TRUE); 25 | if (r == ERR) { 26 | perror ("decr_sem_id"); 27 | return 1; 28 | 29 | } 30 | return 0; 31 | } 32 | 33 | int main (void) { 34 | timeout_t t1, t2, t3; 35 | timeout_t times[NTIMES]; 36 | int i; 37 | char buffer[500]; 38 | t_result r; 39 | 40 | if (init_rusage() != RUSAGE_OK) { 41 | perror("init_rusage"); 42 | exit(1); 43 | } 44 | 45 | /* Create sem */ 46 | r = create_sem_key (21, &semid); 47 | if (r == ERR) { 48 | perror ("create_sem_key"); 49 | exit (1); 50 | } 51 | 52 | /* Do something */ 53 | usleep (1000000); 54 | for (i = 1; i <= 100000; i++) { 55 | if (get_vtime(&t1) != 0) { 56 | perror("get_vtime"); 57 | exit(1); 58 | } 59 | } 60 | 61 | /* Get current time */ 62 | dump_rusage_str ("Start iterations between changes"); 63 | get_time (&t1); 64 | 65 | /* Wait until it changes */ 66 | for (;;) { 67 | get_time (&t2); 68 | if (comp_time(&t1, &t2) != 0) { 69 | break; 70 | } 71 | } 72 | 73 | /* Wait until it changes */ 74 | for (i = 1; ; i++) { 75 | get_time (&t3); 76 | if (comp_time(&t3, &t2) != 0) { 77 | break; 78 | } 79 | } 80 | 81 | /* Compute delta */ 82 | (void) sub_time (&t3, &t2); 83 | 84 | /* Display result */ 85 | sprintf (buffer, "Changes after %d iterations", i); 86 | dump_rusage_str (buffer); 87 | 88 | /* Mesure time for decr_sem, gettimeofday, incr_sem */ 89 | dump_rusage_str ("Start 1000000 cycles decr_sem&gettimeofday&incr_sem"); 90 | for (i = 1; i <= 1000000; i++) { 91 | if (get_vtime(&t1) != 0) { 92 | perror("get_vtime"); 93 | exit(1); 94 | } 95 | } 96 | dump_rusage_str ("After 1000000 cycles decr_sem&gettimeofday&incr_sem"); 97 | 98 | /* Mesure time for gettimeofday */ 99 | dump_rusage_str ("Start 1000000 cycles gettimeofday"); 100 | for (i = 1; i <= 1000000; i++) { 101 | get_time (&t3); 102 | } 103 | dump_rusage_str ("After 1000000 cycles gettimeofday"); 104 | 105 | /* Mesure time of usleep 1, 10, 100, 1000, 100000, 1000000 */ 106 | dump_rusage_str ("Start usleep 1, 10, 100, 1000, 10000, 100000, 1000000"); 107 | usleep (1); 108 | dump_rusage_str ("After usleep 1"); 109 | usleep (10); 110 | dump_rusage_str ("After usleep 10"); 111 | usleep (100); 112 | dump_rusage_str ("After usleep 100"); 113 | usleep (1000); 114 | dump_rusage_str ("After usleep 1000"); 115 | usleep (10000); 116 | dump_rusage_str ("After usleep 10000"); 117 | usleep (100000); 118 | dump_rusage_str ("After usleep 100000"); 119 | usleep (1000000); 120 | dump_rusage_str ("After usleep 1000000"); 121 | 122 | /* Several successive gettimeofday */ 123 | for (i = 0; i < NTIMES; i++) { 124 | get_time(×[i]); 125 | } 126 | for (i = 0; i < NTIMES; i++) { 127 | sprintf(buffer, "Gettime[%04d] -> %06ld.%06ld\n", i, times[i].tv_sec, times[i].tv_usec); 128 | dump_rusage_str (buffer); 129 | } 130 | 131 | /* Delete sem & exit */ 132 | delete_sem_id (semid); 133 | return 0; 134 | } 135 | 136 | -------------------------------------------------------------------------------- /gettimeofdays/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DINCL := boolean 4 | DLIBA := rusage timeval sem_util 5 | 6 | EXES := gettimeofdays 7 | 8 | include $(TEMPLATES)/c.mk 9 | 10 | -------------------------------------------------------------------------------- /gorgy/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DINCL := boolean 4 | DLIBA := timeval sig_util socket mutex 5 | 6 | LIBS := libtty libudp 7 | OBJS_libtty := tty 8 | OBJS_libudp := udp 9 | 10 | EXES := serial_spy gorgy 11 | CARGS_serial_spy := -DSTANDARD 12 | LIBS_serial_spy := libtty 13 | CARGS_gorgy := -DSTANDARD 14 | LIBS_gorgy := libtty libudp 15 | 16 | include $(TEMPLATES)/c.mk 17 | 18 | -------------------------------------------------------------------------------- /gorgy/serial_spy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "tty.h" 5 | 6 | #define BUFFER_SIZE 1000 7 | 8 | 9 | 10 | extern int fd; 11 | static unsigned char buffer[BUFFER_SIZE]; 12 | static unsigned int index; 13 | 14 | static void store (unsigned char oct) { 15 | if (index == BUFFER_SIZE - 1) { 16 | index = 0; 17 | } 18 | buffer[index] = oct; 19 | index ++; 20 | } 21 | 22 | static void print (char oct) { 23 | if (oct < 32) printf ("'%02X' ", (int)oct); 24 | else printf ("%c ", oct); 25 | } 26 | 27 | static void flush (void) { 28 | unsigned int i; 29 | 30 | for (i = 0; i < index; i++) { 31 | print (buffer[i]); 32 | } 33 | printf ("\n"); 34 | fflush(stdout); 35 | index = 0; 36 | } 37 | 38 | 39 | int main(int argc, char *argv[]) { 40 | unsigned char oct; 41 | #if defined(DACOTA) 42 | unsigned char prev_oct, prev_prev_oct; 43 | #endif 44 | 45 | int started; 46 | 47 | if ( argc != 2) { 48 | printf ("SYNTAX ERROR. Usage : serial_spy ::::\n"); 49 | exit (1); 50 | } 51 | 52 | init_tty(argv[1], 1); 53 | 54 | started = 0; 55 | #if defined(DACOTA) 56 | prev_oct = '0'; 57 | prev_prev_oct = '0'; 58 | #endif 59 | index = 0; 60 | 61 | for(;;) { 62 | read_tty (&oct, 1); 63 | #if defined(STANDARD) || defined(TAAATS) 64 | if (oct == 0x02) started = 1; 65 | if (started) { 66 | store (oct); 67 | if (oct == 0x0d) flush(); 68 | } 69 | #elif defined(PALLAS) 70 | if (oct == 'T') started = 1; 71 | if (started) { 72 | store (oct); 73 | if (oct == 0x0a) flush (); 74 | } 75 | #elif defined(DACOTA) 76 | if (oct == 0x01) started = 1; 77 | if (started) { 78 | if ( (oct == 0x01) && (prev_prev_oct == 0x04) ) flush (); 79 | store (oct); 80 | } 81 | prev_prev_oct = prev_oct; 82 | prev_oct = oct; 83 | #else 84 | define STANDARD or TAAATS or PALLAS or DACOTA 85 | #endif 86 | } 87 | } 88 | 89 | -------------------------------------------------------------------------------- /gorgy/tty.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "tty.h" 12 | #define TTY_DEV "/dev/tty" 13 | 14 | #define EXIT { \ 15 | printf ("TTY specification ERROR\n"); \ 16 | printf ("::::\n"); \ 17 | printf (" example : 00:1:7:EVEN:9600\n"); \ 18 | exit (1); \ 19 | } 20 | 21 | int fd; 22 | static char tty_spec[50]; 23 | static int start; 24 | static int last; 25 | 26 | static void parse (char *arg) { 27 | 28 | int i; 29 | 30 | last = (int)strlen(arg); 31 | if (last > (int)sizeof(tty_spec)-1) { 32 | EXIT; 33 | } 34 | strcpy (tty_spec, arg); 35 | for (i = 0; i < last; i++) { 36 | if (tty_spec[i] == ':') { 37 | tty_spec[i] = '\0'; 38 | } 39 | } 40 | start = 0; 41 | } 42 | 43 | static void next (void) { 44 | do { 45 | start++; 46 | } while (tty_spec[start]!='\0' ); 47 | 48 | if (start == last) { 49 | start = -1; 50 | } else { 51 | start ++; 52 | } 53 | 54 | } 55 | 56 | 57 | 58 | void init_tty (char *arg, int read) { 59 | 60 | char tty_name[50]; 61 | struct termio mode; 62 | 63 | unsigned short c_flags; 64 | 65 | parse (arg); 66 | 67 | strcpy (tty_name, TTY_DEV); 68 | strcat (tty_name, &tty_spec[start]); 69 | 70 | next (); if (start == -1) EXIT; 71 | if (strcmp(&tty_spec[start], "1") == 0) c_flags = 0; 72 | else if (strcmp(&tty_spec[start], "2") == 0) c_flags = CSTOPB; 73 | else EXIT; 74 | 75 | 76 | next (); if (start == -1) EXIT; 77 | if (strcmp(&tty_spec[start], "7") == 0) c_flags |= CS7; 78 | else if (strcmp(&tty_spec[start], "8") == 0) c_flags |= CS8; 79 | else EXIT; 80 | 81 | next (); if (start == -1) EXIT; 82 | if (strcmp(&tty_spec[start], "NONE") == 0) ; 83 | else if (strcmp(&tty_spec[start], "ODD") == 0) c_flags |= (PARENB | PARODD); 84 | else if (strcmp(&tty_spec[start], "EVEN") == 0) c_flags |= PARENB; 85 | else EXIT; 86 | 87 | next (); if (start == -1) EXIT; 88 | if (strcmp(&tty_spec[start], "300") == 0) c_flags |= B300; 89 | else if (strcmp(&tty_spec[start], "600") == 0) c_flags |= B600; 90 | else if (strcmp(&tty_spec[start], "1200") == 0) c_flags |= B1200; 91 | else if (strcmp(&tty_spec[start], "1800") == 0) c_flags |= B1800; 92 | else if (strcmp(&tty_spec[start], "2400") == 0) c_flags |= B2400; 93 | else if (strcmp(&tty_spec[start], "4800") == 0) c_flags |= B4800; 94 | else if (strcmp(&tty_spec[start], "9600") == 0) c_flags |= B9600; 95 | else if (strcmp(&tty_spec[start], "19200") == 0) c_flags |= B19200; 96 | else if (strcmp(&tty_spec[start], "38400") == 0) c_flags |= B38400; 97 | 98 | next (); if (start != -1) EXIT; 99 | 100 | if (read) { 101 | fd = open (tty_name, O_RDONLY); 102 | } else { 103 | fd = open (tty_name, O_WRONLY); 104 | } 105 | if (fd < 0) { 106 | perror ("Error open"); 107 | fprintf (stderr, ">%s<\n", tty_name); 108 | exit(-1); 109 | } 110 | 111 | if (ioctl (fd, TCGETA, (char*) &mode) <0) { 112 | perror ("Error ioctl get"); 113 | exit (-1); 114 | } 115 | mode.c_iflag = 0; 116 | mode.c_oflag = 0; 117 | mode.c_lflag = 0; 118 | mode.c_cflag = (CLOCAL | HUPCL | c_flags); 119 | if (read) { 120 | mode.c_cflag = (mode.c_cflag | CREAD); 121 | } 122 | mode.c_cc[VMIN] = 1; 123 | mode.c_cc[VTIME] = 0; 124 | 125 | if (ioctl (fd, TCSETA, (char*) &mode) <0) { 126 | perror ("Error ioctl set"); 127 | exit (-1); 128 | } 129 | 130 | printf ("TTY %s initialised.\n", tty_name); 131 | 132 | } 133 | 134 | 135 | void send_tty (char *msg, int len) { 136 | 137 | int cr; 138 | 139 | for (;;) { 140 | cr = (write (fd, msg, len) >= 0); 141 | if (cr) return; 142 | if (errno != EINTR) { 143 | perror ("write"); 144 | return; 145 | } 146 | } 147 | } 148 | 149 | void read_tty (void *buffer, int nbre_octet) { 150 | int i; 151 | char *p; 152 | int res; 153 | 154 | for (i=0, p=(char*)buffer; i 2 | #include 3 | 4 | #include "socket.h" 5 | #include "udp.h" 6 | 7 | static soc_token soc = NULL; 8 | 9 | void init_udp (char *port_name_no) { 10 | 11 | int port_no; 12 | int cr; 13 | char lan_name[80]; 14 | 15 | if (soc_get_local_lan_name(lan_name, sizeof(lan_name)) != SOC_OK) { 16 | perror("getting lan name"); 17 | exit (2); 18 | } 19 | 20 | soc = init_soc; 21 | 22 | 23 | if (soc_open(&soc, udp_socket) != SOC_OK) { 24 | perror ("opening socket"); 25 | exit (2); 26 | } 27 | 28 | if (isdigit(port_name_no[0])) { 29 | port_no = 0; 30 | port_no = atoi(port_name_no); 31 | if (port_no == 0) { 32 | fprintf (stderr, "Wrong port number >%s<\n", port_name_no); 33 | exit (2); 34 | } else { 35 | cr = soc_set_dest_name_port (soc, lan_name, true, (soc_port) port_no); 36 | } 37 | } else { 38 | cr = soc_set_dest_name_service (soc, lan_name, true, port_name_no); 39 | } 40 | 41 | if (cr != SOC_OK) { 42 | perror ("setting detination"); 43 | exit (2); 44 | } 45 | 46 | if (soc_get_dest_port(soc, (soc_port*) &port_no) != SOC_OK) { 47 | perror ("getting port no"); 48 | exit (2); 49 | } 50 | 51 | printf ("UDP port no %d initialised.\n", port_no); 52 | 53 | } 54 | 55 | void send_udp (char *msg, int len) { 56 | 57 | if (soc_send (soc, (soc_message) msg, (soc_length) len) != SOC_OK) 58 | perror ("sending"); 59 | } 60 | 61 | -------------------------------------------------------------------------------- /gorgy/udp.h: -------------------------------------------------------------------------------- 1 | void init_udp (char *port_name_no); 2 | 3 | void send_udp (char *msg, int len); 4 | -------------------------------------------------------------------------------- /html2ascii/html2ascii.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "get_line.h" 7 | 8 | /* Remove all <....> from a file (argv[1]). Save in -ascii */ 9 | /* Or read stdin and write on stdout */ 10 | /* Skip all leading spaces */ 11 | /* Replace each sequence if 5 spaces within line by 1 space */ 12 | 13 | #define BUFFER_SIZE 1024 14 | 15 | static void error (const char *prog, const char *msg) 16 | __attribute__((noreturn)); 17 | static void error (const char *prog, const char *msg) { 18 | fprintf (stderr, "ERROR: %s.\n", msg); 19 | fprintf (stderr, "Usage: %s [ ]\n", prog); 20 | exit(1); 21 | } 22 | 23 | const char sstart[] = "Vos Documents au format PDF:"; 24 | const char sstop[] = " "; 25 | 26 | 27 | int main (int argc, char *argv[]) { 28 | 29 | FILE *fin, *fout; 30 | char out_file_name[1024]; 31 | char buffer[BUFFER_SIZE]; 32 | int len; 33 | int i, j; 34 | int skip, sskip; 35 | int nb_space; 36 | int leading; 37 | int nb_empty; 38 | 39 | if (argc > 2) { 40 | error (argv[0], "invalid arguments"); 41 | } 42 | 43 | if (argc == 1) { 44 | fin = stdin; 45 | fout = stdout; 46 | } else { 47 | fin = fopen (argv[1], "r"); 48 | if (fin == (FILE*) NULL) { 49 | error (argv[0], "can't open input file"); 50 | } 51 | strcpy (out_file_name, argv[1]); 52 | strcat (out_file_name, "-ascii"); 53 | fout = fopen (out_file_name, "w"); 54 | if (fout == (FILE*) NULL) { 55 | fclose (fin); 56 | error (argv[0], "can't create output file"); 57 | } 58 | } 59 | 60 | skip = 0; 61 | sskip = 0; 62 | nb_empty = 0; 63 | for (;;) { 64 | 65 | nb_space = 0; 66 | leading = 1; 67 | len = get_line (fin, buffer, BUFFER_SIZE); 68 | if (len == -1) { 69 | break; 70 | } 71 | j = 0; 72 | for (i = 0; i <= len; i++) { 73 | if (buffer[i] == '<') { 74 | skip = 1; 75 | } else if (buffer[i] == '>') { 76 | skip = 0; 77 | } else { 78 | 79 | if (!skip) { 80 | /* We're out of < .. > */ 81 | /* Skip all leading spaces */ 82 | if (buffer[i] == ' ') { 83 | if (! leading) { 84 | /* Within line, 5 spaces become 1 space */ 85 | nb_space ++; 86 | if (nb_space == 5) { 87 | j -= 4; 88 | nb_space = 0; 89 | } 90 | } 91 | } else { 92 | /* One significant character: within line, no more space */ 93 | leading = 0; 94 | nb_space = 0; 95 | } 96 | if (!leading) { 97 | if (buffer[i] == (char)0xE9) { 98 | buffer[j] = 'e'; 99 | j++; 100 | } else { 101 | buffer[j] = buffer[i]; 102 | j++; 103 | } 104 | } 105 | } 106 | 107 | } 108 | } 109 | /* Now check super start and super stop */ 110 | if ( (sskip == 0) && (strncmp(buffer, sstart, strlen(sstart)) == 0) ) { 111 | sskip = 1; 112 | } 113 | if ( (sskip == 1) && (strncmp(buffer, sstop, strlen(sstop)) == 0) ) { 114 | sskip = 2; 115 | } 116 | if (sskip == 1) { 117 | /* Only one empty line */ 118 | if (strlen(buffer) == 0) { 119 | nb_empty ++; 120 | } else { 121 | nb_empty = 0; 122 | } 123 | if (nb_empty <= 1) { 124 | fprintf (fout, "%s\n", buffer); 125 | } 126 | } 127 | } 128 | 129 | 130 | if (argc != 1) { 131 | fclose (fin); 132 | fclose (fout); 133 | } 134 | exit(0); 135 | } 136 | 137 | -------------------------------------------------------------------------------- /html2ascii/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DLIBA := get_line 4 | 5 | EXES := html2ascii 6 | 7 | include $(TEMPLATES)/c.mk 8 | 9 | -------------------------------------------------------------------------------- /init_so/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | LIBS := libmodule1 libmodule2 4 | OBJS_libmodule1 := module1 5 | OBJS_libmodule2 := module2 6 | 7 | EXES := try 8 | LARGS_try := -L$(LIB) -lmodule1 -lmodule2 9 | 10 | include $(TEMPLATES)/c.mk 11 | 12 | -------------------------------------------------------------------------------- /init_so/module1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "module1.h" 3 | 4 | extern void __init_11(void); 5 | extern void __init_12(void); 6 | extern void _init(void); 7 | 8 | extern void __init_11(void) { 9 | printf ("Init 11\n"); 10 | } 11 | 12 | extern void __init_12(void) { 13 | printf ("Init 12\n"); 14 | } 15 | 16 | extern void _init(void) { 17 | printf ("Init 1\n"); 18 | } 19 | 20 | extern void func1(void) { 21 | printf ("Func 1\n"); 22 | } 23 | 24 | -------------------------------------------------------------------------------- /init_so/module1.h: -------------------------------------------------------------------------------- 1 | 2 | extern void func1(void); 3 | -------------------------------------------------------------------------------- /init_so/module2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "module2.h" 3 | 4 | extern void __init_21(void); 5 | extern void __init_22(void); 6 | extern void _init(void); 7 | 8 | extern void __init_21(void) { 9 | printf ("Init 21\n"); 10 | } 11 | 12 | extern void __init_22(void) { 13 | printf ("Init 22\n"); 14 | } 15 | 16 | extern void _init(void) { 17 | printf ("Init 2\n"); 18 | } 19 | 20 | extern void func2(void) { 21 | printf ("Func 2\n"); 22 | } 23 | 24 | -------------------------------------------------------------------------------- /init_so/module2.h: -------------------------------------------------------------------------------- 1 | 2 | extern void func2(void); 3 | -------------------------------------------------------------------------------- /init_so/try.c: -------------------------------------------------------------------------------- 1 | #include "module1.h" 2 | #include "module2.h" 3 | 4 | int main (void) { 5 | func1(); 6 | func2(); 7 | return 0; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /ipm/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DINCL := boolean 4 | DLIBA := socket mutex 5 | 6 | EXES := tipm 7 | 8 | include $(TEMPLATES)/c.mk 9 | 10 | -------------------------------------------------------------------------------- /ipm/tipm.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /* Send a packet on lan "test_ipm" and port "test_udp" */ 6 | 7 | #include "socket.h" 8 | #define SIZE 8*1024 9 | char buff[10000000]; 10 | 11 | static void error (const char *call, int res) __attribute__ ((noreturn)); 12 | static void error (const char *call, int res) { 13 | perror (call); 14 | fprintf (stderr, "Error %d\n", res); 15 | exit (1); 16 | } 17 | 18 | int main (int argc, char *argv[]) { 19 | soc_token socket = NULL; 20 | int res; 21 | int size = 0; 22 | 23 | if (argc > 1) { 24 | size = atoi(argv[1]); 25 | } 26 | if (size == 0) { 27 | size = SIZE; 28 | } 29 | 30 | res = soc_open(&socket, udp_socket); 31 | if (res != SOC_OK) error("soc_open", res); 32 | 33 | res = soc_set_dest_name_service (socket, "test_ipm", TRUE, "test_udp"); 34 | if (res != SOC_OK) error("soc_set_dest_name_service", res); 35 | 36 | printf ("Sending %d bytes\n", size); 37 | res = soc_send (socket, (soc_message)buff, (soc_length)size); 38 | if (res != SOC_OK) error("soc_send", res); 39 | printf ("Done.\n"); 40 | 41 | return 0; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /ipx/ipx.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | /* Display IP address in hexa, in 4 bytes and host name */ 8 | 9 | #include "socket.h" 10 | 11 | static void print_ip (soc_host *host, char *name) { 12 | int i; 13 | 14 | for (i = 0; i <= 3; i++) { 15 | printf ("%02X", host->bytes[i]); 16 | } 17 | printf (" <==> "); 18 | for (i = 0; i <= 3; i++) { 19 | printf ("%d", host->bytes[i]); 20 | if (i != 3) { 21 | printf ("."); 22 | } 23 | } 24 | printf (" <==> "); 25 | if (name[0] == '\0') { 26 | printf ("?"); 27 | } else { 28 | printf ("%s", name); 29 | } 30 | printf ("\n"); 31 | } 32 | 33 | static byte b2h (char c) { 34 | if ( (c >= '0') && (c <= '9') ) { 35 | return c - '0'; 36 | } else if ( (c >= 'a') && (c <= 'f') ) { 37 | return 10 + c - 'a'; 38 | } else if ( (c >= 'A') && (c <= 'F') ) { 39 | return 10 + c - 'A'; 40 | } else { 41 | return 0; 42 | } 43 | } 44 | 45 | char host_name[MAXHOSTNAMELEN]; 46 | 47 | static void do_one (char *host_name) { 48 | int i; 49 | int res; 50 | char c; 51 | soc_host host; 52 | 53 | /* Try with host name or ip notation */ 54 | if ( (res = soc_host_of (host_name, &host) ) == SOC_OK) { 55 | if (soc_host_name_of (&host, host_name, sizeof(host_name)) != SOC_OK) { 56 | /* Host not found */ 57 | host_name[0] = '\0'; 58 | } 59 | print_ip (&host, host_name); 60 | } else if (strlen (host_name) == 8) { 61 | /* Try with 8 hexa digits */ 62 | res = 0; 63 | for (i = 0; i < 8; i++) { 64 | c = host_name[i]; 65 | if ( ( (c >= '0') && (c <= '9') ) 66 | || ( (c >= 'a') && (c <= 'f') ) 67 | || ( (c >= 'A') && (c <= 'F') ) ) { 68 | ; 69 | } else { 70 | res = 1; 71 | } 72 | } 73 | if (res == 0) { 74 | /* Looks like a host id */ 75 | for (i = 0; i < 8; i++, i++) { 76 | host.bytes[i/2] = (b2h(host_name[i]) * 16) + b2h(host_name[i+1]); 77 | } 78 | if (soc_host_name_of (&host, host_name, sizeof(host_name)) != SOC_OK) { 79 | /* Host not found */ 80 | host_name[0] = '\0'; 81 | } 82 | print_ip (&host, host_name); 83 | } else { 84 | fprintf (stderr, "Invalid argument %s\n", host_name); 85 | } 86 | } 87 | } 88 | 89 | int main (int argc, char *argv[]) { 90 | 91 | int i; 92 | int res; 93 | 94 | if (argc == 1) { 95 | /* No arg => local host */ 96 | if ( (res = soc_get_local_host_name (host_name, sizeof(host_name)) ) == SOC_OK) { 97 | do_one (host_name); 98 | } else { 99 | fprintf (stderr, "soc_get_local_host_name -> %d\n", res); 100 | exit (1); 101 | } 102 | } else if (strcmp (argv[1], "-h") == 0) { 103 | printf ("Usage: %s [ { | | } ]\n", 104 | basename(argv[0])); 105 | exit (2); 106 | } else { 107 | /* Dump each argument */ 108 | for (i = 1; i < argc; i++) { 109 | do_one (argv[i]); 110 | } 111 | } 112 | exit (0); 113 | } 114 | 115 | -------------------------------------------------------------------------------- /ipx/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DINCL := boolean 4 | DLIBA := socket mutex 5 | 6 | EXES := ipx 7 | 8 | include $(TEMPLATES)/c.mk 9 | 10 | -------------------------------------------------------------------------------- /locale/locale.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /* Display ASCII characters within locale */ 6 | 7 | #define ALL 1 8 | #define ONE 0 9 | 10 | static void draw (char *str[], int count, char param); 11 | static void help(char *str[]); 12 | 13 | int main (int argc, char *argv[]) { 14 | 15 | (void) setlocale(LC_ALL, ""); 16 | 17 | if ( argc < 2 ) help(argv); 18 | else draw (argv, argc, ONE); 19 | exit(0); 20 | } 21 | 22 | static void help (char *str[]) { 23 | printf ("-- usage : \n"); 24 | printf (" ascii [ARG]\n"); 25 | printf (" where ARG is a character or a string\n"); 26 | printf (" if no argument is specified \n"); 27 | printf (" print the whole ascii table\n\n"); 28 | draw (str, ALL, ' '); 29 | } 30 | 31 | static void draw (char *str[], int count, char param) { 32 | int j=0, i=0; 33 | 34 | printf ("+-----------+-----+-----+-----+\n"); 35 | printf ("| character | dec | oct | hex |\n"); 36 | printf ("+-----------+-----+-----+-----+\n"); 37 | 38 | if ( param == ONE ) 39 | { 40 | for ( j = 1; j < count; ) 41 | { 42 | i = 0; 43 | while ( str[j][i] != '\0' ) 44 | { 45 | printf ("| %c | %3d | %3o | %3X |\n", str[j][i], str[j][i], str[j][i], str[j][i]); 46 | i++; 47 | } 48 | if ( j < count - 1) printf ("+-----------+-----+-----+-----+\n"); 49 | j++; 50 | } 51 | } 52 | else 53 | { 54 | for ( i = 32; i < 256; i++) 55 | { 56 | printf ("| %c | %3d | %3o | %3X |\n", i, i, i, i); 57 | } 58 | } 59 | 60 | printf ("+-----------+-----+-----+-----+\n"); 61 | 62 | } 63 | 64 | -------------------------------------------------------------------------------- /locale/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | EXES := locale 4 | 5 | include $(TEMPLATES)/c.mk 6 | 7 | -------------------------------------------------------------------------------- /localtime/localtime.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main (void) { 7 | 8 | time_t t1, t2; 9 | struct tm *ptm; 10 | 11 | t1 = time(&t2); 12 | 13 | printf ("time %d %d\n", (int)t1, (int)t2); 14 | 15 | ptm = localtime(&t1); 16 | 17 | printf ("localtime %d:%d\n", ptm->tm_hour, ptm->tm_min); 18 | 19 | exit (0); 20 | } 21 | -------------------------------------------------------------------------------- /localtime/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | EXES := localtime 4 | 5 | include $(TEMPLATES)/c.mk 6 | 7 | -------------------------------------------------------------------------------- /lzf/.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | config.h 3 | config.log 4 | config.status 5 | *.o 6 | *.a 7 | lzf 8 | -------------------------------------------------------------------------------- /lzf/Changes: -------------------------------------------------------------------------------- 1 | 3.6 Mon Feb 7 17:37:31 CET 2011 2 | - fixed hash calculation in C♯ version (Tiago Freitas Leal). 3 | - unroll copy for small sizes, use memcpy for larger sizes, 4 | greatly speeding up decompression in most cases. 5 | - finally disable rep movsb - it's a big loss on modern intel cpus, 6 | and only a small win on amd cpus. 7 | - improve C++ compatibility of the code. 8 | - slightly improve compressor speed. 9 | - halved memory requirements for compressor on 64 bit architectures, 10 | which can improve the speed quite a bit on older cpus. 11 | 12 | 3.5 Fri May 1 02:28:42 CEST 2009 13 | - lzf_compress did sometimes write one octet past the given output 14 | buffer (analyzed and nice testcase by Salvatore Sanfilippo). 15 | 16 | 3.4 Tue Sep 2 06:45:00 CEST 2008 17 | - the fix from 3.3 introduced a compression bug, which is fixed in 18 | this release (which explains the mysterious prerelease...). Thanks 19 | once more to Clément Calmels. 20 | 21 | 3.3 Mon Aug 25 03:17:42 CEST 2008 22 | - lzf_compress could access memory after the given input buffer 23 | when outputting back references. reported with nice testcase 24 | by Clément Calmels. 25 | 26 | 3.2 Fri May 9 18:52:23 CEST 2008 27 | - include a workaround for failing POSIX and real-world compliance 28 | on 64 bit windows (microsoft claims to support POSIX, but is far 29 | from it). (bug found and analysed nicely by John Lilley). 30 | 31 | 3.1 Fri Nov 30 11:33:04 CET 2007 32 | - IMPORTANT BUGFIX: a too long final literal run would corrupt data 33 | in the encoder (this was introduced in 3.0 only, earlier versions 34 | are safe). 35 | 36 | 3.0 Tue Nov 13 22:13:09 CET 2007 37 | - switched to 2-clause bsd with "GPL v2 or any later version" option. 38 | - speed up compression by ~10-15% in common cases 39 | by some manual unrolling. 40 | - import some compiler tricks from JSON::XS, for further speed-ups. 41 | - tune hash functions depending on ULTRA_FAST or VERY_FAST settings. 42 | - for typical binary data (e.g. /bin/bash, memory dumps, 43 | canterbury corpus etc.), speed is now comparable to fastlz, but 44 | with better compression ratio. with ULTRA_FAST, it's typically 45 | 3-15% faster than fastlz while still maintaining a similar ratio. 46 | (amd64 and core 2 duo, ymmv). thanks a lot for the competition :) 47 | - undo inline assembly in compressor, it is no longer helpful. 48 | - no changes to the decompressor. 49 | - use a HLOG of 16 by default now (formerly 15). 50 | 51 | 2.1 Fri Nov 2 13:34:42 CET 2007 52 | - switched to a 2-clause bsd license with GPL exception. 53 | - get rid of memcpy. 54 | - tentatively use rep movsb on x86 and x86_64 (gcc only) for a 55 | moderate speed improvement. 56 | - applied patch by Kein-Hong Man to maske lzf.c compile under 57 | the crippled mingw32 environment. 58 | 59 | 2.0 Fri Feb 16 23:11:18 CET 2007 60 | - replaced lzf demo by industrial-strength lzf utility with behaviour 61 | similar other compression utilities. Thanks for Stefan Traby for 62 | rewriting it! 63 | - fix state arg prototype. 64 | 65 | 1.7 Wed Sep 27 17:29:15 CEST 2006 66 | - remove bogus "unlzf" patch. 67 | note to self: never accept well-meant patches. 68 | - make lzf more robust in presence of padding bytes or sudden eof. 69 | 70 | 1.6 Fri Jul 7 17:31:26 CEST 2006 71 | - the lzf example utility will now uncompress if invoked 72 | as "unlzf" (patch by Scott Feeney). 73 | - add CHECK_INPUT option that adds more checks for input 74 | data validity. 75 | - help applications that do not pass in the correct length 76 | (such as php) by returning either EINVAL or E2BIG. 77 | - default HLOG size is now 15 (cpu caches have increased). 78 | - documentation fixes. 79 | 80 | 1.51 Thu Apr 14 22:15:46 CEST 2005 81 | - incorporated C♯ implementation of both the en- and decoder, 82 | written by "Oren J. Maurice". 83 | You can find it in the cs/ subdirectory. 84 | - make FRST, NEXT IDX overridable if lzf_c.c is directly included 85 | in the code. 86 | 87 | 1.5 Tue Mar 8 20:23:23 CET 2005 88 | - incorporated improvements by Adam D. Moss, 89 | which includes a new VERY_FAST mode which is 90 | a bit slower than ULTRA_FAST but much better, 91 | and enabled it as default. 92 | 93 | 1.401 Thu Mar 3 18:00:52 CET 2005 94 | - use cstring in c++, not string.h. 95 | - change of contact address. 96 | 97 | 1.4 Wed Dec 15 08:08:49 CET 2004 98 | - very very slight tuning of the hashing function. 99 | 100 | 1.3 Thu Mar 25 15:41:17 CET 2004 101 | - changed license of lzf core code to explicitly allow 102 | relicensing under the GPLv2. 103 | - added VPATH support as suggested by Björn Eriksson. 104 | 105 | 1.2 Mon Dec 29 13:47:28 CET 2003 106 | - avoid spurious memory accesses after the to-be-compressed 107 | memory region. originally reported by Michal Zalewski. 108 | - flip LZF_STACK_ARG meaning (to be correct). 109 | 110 | 1.1 Tue Dec 23 05:48:32 CET 2003 111 | - removed #warn directive, it's not worth the hassle. 112 | - add LZF_STACK_ARG and AVOID_ERRNO configurations 113 | for embedded systems. 114 | - make it compile cleanly as c++. 115 | - some small documentation and code fixes. 116 | 117 | 1.0 Sun Nov 17 12:37:37 CET 2002 118 | - slightly better compression ratio, almost unmeasurably 119 | slower. 120 | - some documentation fixes. 121 | 122 | 0.4 Thu Jun 13 14:11:10 CEST 2002 123 | - typoe fix. 124 | - lzf demo program now properly decompresses small files. 125 | - fix another 64 bit issue, found by Laurent Deniel. 126 | 127 | 0.3 Tue Jan 16 13:21:14 CET 2001 128 | - fix silly beginners 32/64 bit mistake. 129 | 130 | 0.2 Thu Jan 4 05:56:42 CET 2001 131 | - now totally independent of autoconfig, for 132 | easy inclusion into other programs. 133 | - much better fine-tuning, faster and better than 0.1. 134 | 135 | 0.1 2000 136 | - initial release. 137 | -------------------------------------------------------------------------------- /lzf/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2000-2009 Marc Alexander Lehmann 2 | 3 | Redistribution and use in source and binary forms, with or without modifica- 4 | tion, are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 14 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- 15 | CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 16 | EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- 17 | CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 19 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 20 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- 21 | ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 22 | OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | Alternatively, the following files carry an additional notice that 25 | explicitly allows relicensing under the GPLv2: lzf.c lzf.h lzfP.h lzf_c.c 26 | lzf_d.c 27 | 28 | -------------------------------------------------------------------------------- /lzf/Makefile.in: -------------------------------------------------------------------------------- 1 | VERSION = 3.6 2 | 3 | prefix = @prefix@ 4 | exec_prefix = @exec_prefix@ 5 | libdir = @libdir@ 6 | bindir = @bindir@ 7 | includedir = @includedir@ 8 | 9 | VPATH = @srcdir@ 10 | 11 | CC = @CC@ 12 | CPPFLAGS = -I. @CPPFLAGS@ 13 | CFLAGS = @CFLAGS@ 14 | LDFLAGS = @LDFLAGS@ 15 | RANLIB = @RANLIB@ 16 | INSTALL = @INSTALL@ 17 | INSTALL_DATA = @INSTALL_DATA@ 18 | 19 | all: Makefile lzf 20 | 21 | clean: 22 | -rm -f *.o *.a lzf bench 23 | 24 | lzf_c.o: lzf_c.c lzfP.h 25 | 26 | lzf_d.o: lzf_d.c lzfP.h 27 | 28 | lzf.o: lzf.c 29 | 30 | lzf: lzf.o liblzf.a 31 | 32 | lzfP.h: lzf.h config.h 33 | 34 | liblzf.a: lzf_c.o lzf_d.o 35 | rm -f $@ 36 | $(AR) rc $@ $^ 37 | $(RANLIB) $@ 38 | 39 | install: all 40 | $(INSTALL) -d $(bindir) 41 | $(INSTALL) -m 755 lzf $(bindir) 42 | $(INSTALL) -d $(includedir) 43 | $(INSTALL_DATA) lzf.h $(includedir) 44 | $(INSTALL) -d $(libdir) 45 | $(INSTALL_DATA) liblzf.a $(libdir) 46 | 47 | dist: 48 | mkdir liblzf-$(VERSION) 49 | tar c LICENSE README Makefile.in config.h.in \ 50 | configure configure.ac install-sh \ 51 | cs/README cs/CLZF.cs \ 52 | lzf.h lzfP.h lzf_c.c lzf_d.c \ 53 | crc32.h lzf.c Changes \ 54 | | tar xpC liblzf-$(VERSION) 55 | -chown -R root.root liblzf-$(VERSION) 56 | chmod -R u=rwX,go=rX liblzf-$(VERSION) 57 | tar cvf - liblzf-$(VERSION) | gzip -9 >liblzf-$(VERSION).tar.gz 58 | rm -rf liblzf-$(VERSION) 59 | ls -l liblzf-$(VERSION).tar.gz 60 | 61 | Makefile: Makefile.in 62 | ./config.status 63 | 64 | bench: Makefile liblzf.a bench.c 65 | $(CC) $(CPPFLAGS) $(CFLAGS) -g -o bench bench.c -L. -llzf 66 | 67 | -------------------------------------------------------------------------------- /lzf/README: -------------------------------------------------------------------------------- 1 | DESCRIPTION 2 | LZF is an extremely fast (not that much slower than a pure memcpy) 3 | compression algorithm. It is ideal for applications where you want to 4 | save *some* space but not at the cost of speed. It is ideal for 5 | repetitive data as well. The module is self-contained and very small. 6 | 7 | It's written in ISO-C with no external dependencies other than what 8 | C provides and can easily be #include'd into your code, no makefile 9 | changes or library builds requires. 10 | 11 | A C♯ implementation without external dependencies is available, too. 12 | 13 | I do not know for certain whether any patents in any countries apply 14 | to this algorithm, but at the moment it is believed that it is free 15 | from any patents. More importantly, it is also free to use in every 16 | software package (see LICENSE). 17 | 18 | See the lzf.h file for details on how the functions in this 19 | mini-library are to be used. 20 | 21 | NOTE: This package contains a very bare-bones command-line utility 22 | which is neither optimized for speed nor for compression. This library 23 | is really intended to be used inside larger programs. 24 | 25 | AUTHOR 26 | This library was written by Marc Lehmann (See also 27 | http://software.schmorp.de/pkg/liblzf). 28 | 29 | 30 | -------------------------------------------------------------------------------- /lzf/config.h.in: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated automatically from configure.in by autoheader 2.13. */ 2 | 3 | /* Define to empty if the keyword does not work. */ 4 | #undef const 5 | 6 | /* Define if you have the ANSI C header files. */ 7 | #undef STDC_HEADERS 8 | 9 | /* The number of bytes in a int. */ 10 | #undef SIZEOF_INT 11 | 12 | /* The number of bytes in a long. */ 13 | #undef SIZEOF_LONG 14 | 15 | /* The number of bytes in a short. */ 16 | #undef SIZEOF_SHORT 17 | -------------------------------------------------------------------------------- /lzf/configure.ac: -------------------------------------------------------------------------------- 1 | AC_INIT 2 | AC_CONFIG_SRCDIR([lzfP.h]) 3 | 4 | AC_CONFIG_HEADER(config.h) 5 | 6 | AC_GNU_SOURCE 7 | AC_SYS_LARGEFILE 8 | AC_PROG_CC 9 | AC_PROG_RANLIB 10 | AC_PROG_INSTALL 11 | AC_HEADER_STDC 12 | 13 | AC_C_CONST 14 | AC_C_INLINE 15 | AC_CHECK_HEADERS(getopt.h) 16 | AC_CHECK_FUNCS(getopt_long) 17 | 18 | if test "$GCC" = yes; then 19 | CFLAGS="$CFLAGS -O3 -funroll-all-loops" 20 | else 21 | AC_MSG_RESULT(no gcc) 22 | fi 23 | 24 | AC_CONFIG_FILES([Makefile]) 25 | AC_OUTPUT 26 | -------------------------------------------------------------------------------- /lzf/crc32.h: -------------------------------------------------------------------------------- 1 | #ifndef CRC32_H 2 | #define CRC32_H 3 | 4 | /* crc32 0xdebb20e3 table and supplementary functions. */ 5 | 6 | static const u32 crc_32_tab[] = 7 | { 8 | 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL, 9 | 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL, 10 | 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL, 11 | 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL, 12 | 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL, 13 | 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL, 14 | 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL, 15 | 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL, 16 | 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL, 17 | 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL, 18 | 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL, 19 | 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL, 20 | 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL, 21 | 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL, 22 | 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL, 23 | 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL, 24 | 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL, 25 | 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL, 26 | 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL, 27 | 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL, 28 | 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL, 29 | 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL, 30 | 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL, 31 | 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL, 32 | 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL, 33 | 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL, 34 | 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL, 35 | 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL, 36 | 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL, 37 | 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL, 38 | 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL, 39 | 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL, 40 | 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL, 41 | 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL, 42 | 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL, 43 | 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL, 44 | 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL, 45 | 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL, 46 | 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL, 47 | 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL, 48 | 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL, 49 | 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL, 50 | 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL, 51 | 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL, 52 | 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL, 53 | 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL, 54 | 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL, 55 | 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL, 56 | 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL, 57 | 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL, 58 | 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL, 59 | 0x2d02ef8dL 60 | }; 61 | 62 | #define crc32(crc,byte) (crc_32_tab[(u8)(crc) ^ (u8)(byte)] ^ ((crc) >> 8)) 63 | 64 | #endif 65 | 66 | -------------------------------------------------------------------------------- /lzf/cs/README: -------------------------------------------------------------------------------- 1 | The C♯ implementation of the LZF en-/decoder functions in this 2 | directory was written (and is maintained) by 3 | 4 | Oren J. Maurice . 5 | 6 | If you have any questions or improvements, you should contact the 7 | original author (and maybe CC me, Marc Lehmann ). 8 | -------------------------------------------------------------------------------- /lzf/lzf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2008 Marc Alexander Lehmann 3 | * 4 | * Redistribution and use in source and binary forms, with or without modifica- 5 | * tion, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- 16 | * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 17 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- 18 | * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 20 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 21 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- 22 | * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 23 | * OF THE POSSIBILITY OF SUCH DAMAGE. 24 | * 25 | * Alternatively, the contents of this file may be used under the terms of 26 | * the GNU General Public License ("GPL") version 2 or any later version, 27 | * in which case the provisions of the GPL are applicable instead of 28 | * the above. If you wish to allow the use of your version of this file 29 | * only under the terms of the GPL and not to allow others to use your 30 | * version of this file under the BSD license, indicate your decision 31 | * by deleting the provisions above and replace them with the notice 32 | * and other provisions required by the GPL. If you do not delete the 33 | * provisions above, a recipient may use your version of this file under 34 | * either the BSD or the GPL. 35 | */ 36 | 37 | #ifndef LZF_H 38 | #define LZF_H 39 | 40 | /*********************************************************************** 41 | ** 42 | ** lzf -- an extremely fast/free compression/decompression-method 43 | ** http://liblzf.plan9.de/ 44 | ** 45 | ** This algorithm is believed to be patent-free. 46 | ** 47 | ***********************************************************************/ 48 | 49 | #define LZF_VERSION 0x0105 /* 1.5, API version */ 50 | 51 | /* 52 | * Compress in_len bytes stored at the memory block starting at 53 | * in_data and write the result to out_data, up to a maximum length 54 | * of out_len bytes. 55 | * 56 | * If the output buffer is not large enough or any error occurs return 0, 57 | * otherwise return the number of bytes used, which might be considerably 58 | * more than in_len (but less than 104% of the original size), so it 59 | * makes sense to always use out_len == in_len - 1), to ensure _some_ 60 | * compression, and store the data uncompressed otherwise (with a flag, of 61 | * course. 62 | * 63 | * lzf_compress might use different algorithms on different systems and 64 | * even different runs, thus might result in different compressed strings 65 | * depending on the phase of the moon or similar factors. However, all 66 | * these strings are architecture-independent and will result in the 67 | * original data when decompressed using lzf_decompress. 68 | * 69 | * The buffers must not be overlapping. 70 | * 71 | * If the option LZF_STATE_ARG is enabled, an extra argument must be 72 | * supplied which is not reflected in this header file. Refer to lzfP.h 73 | * and lzf_c.c. 74 | * 75 | */ 76 | unsigned int 77 | lzf_compress (const void *const in_data, unsigned int in_len, 78 | void *out_data, unsigned int out_len); 79 | 80 | /* 81 | * Decompress data compressed with some version of the lzf_compress 82 | * function and stored at location in_data and length in_len. The result 83 | * will be stored at out_data up to a maximum of out_len characters. 84 | * 85 | * If the output buffer is not large enough to hold the decompressed 86 | * data, a 0 is returned and errno is set to E2BIG. Otherwise the number 87 | * of decompressed bytes (i.e. the original length of the data) is 88 | * returned. 89 | * 90 | * If an error in the compressed data is detected, a zero is returned and 91 | * errno is set to EINVAL. 92 | * 93 | * This function is very fast, about as fast as a copying loop. 94 | */ 95 | unsigned int 96 | lzf_decompress (const void *const in_data, unsigned int in_len, 97 | void *out_data, unsigned int out_len); 98 | 99 | #endif 100 | 101 | -------------------------------------------------------------------------------- /lzf/rlzf: -------------------------------------------------------------------------------- 1 | lzf -b 104857600 -f -r 2 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | SUBDIRS := boolean timeval wait_evt mutex socket socket_evt \ 4 | get_line rusage sem_util sig_util vt100 dynlist \ 5 | adjtime asc catlock cirtail delta_time dos2unix dt font_size forker \ 6 | fread_float gettimeofdays gorgy html2ascii init_so ipm ipx locale mallocer \ 7 | man2file mheap mu pcre pcrypt putvar semctl shm status substit \ 8 | synchro tcpdump term udp_send unlink udpspy 9 | 10 | include $(TEMPLATES)/dir.mk 11 | 12 | -------------------------------------------------------------------------------- /mallocer/lib.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | pthread_t th; 4 | 5 | static void * the_thread (void * arg) { 6 | return arg; 7 | } 8 | 9 | extern void dummy (void); 10 | 11 | extern void dummy (void) { 12 | (void) pthread_create (&th, NULL, &the_thread, NULL); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /mallocer/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DLIBA := rusage 4 | 5 | LIBS := lib_r 6 | EXES := mallocer_m mallocer_h mallocer_r 7 | 8 | OBJS_lib_r := lib 9 | 10 | LIBS_mallocer_m := 11 | LIBS_mallocer_h := lib_r 12 | LIBS_mallocer_r := lib_r 13 | 14 | include $(TEMPLATES)/c.mk 15 | 16 | $(EXES) : $(LIB)/mallocer.o 17 | @if [ "$(LIBS_$(@F))" != "" ]; then \ 18 | make $(patsubst %,$(LIB)/%.a,$(LIBS_$(@F))); \ 19 | fi 20 | @$(ECHO) CC -o $@ $< $(LIBS_$(@F):%=$(LIB)/%.a) $(DLIBAD) $(LARGS_$(@F)) -lpthread -lm 21 | @$(CC) -o $@ $< $(LIBS_$(@F):%=$(LIB)/%.a) $(DLIBAD) $(LARGS_$(@F)) -lpthread -lm 22 | 23 | -------------------------------------------------------------------------------- /mallocer/mallocer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "rusage.h" 8 | 9 | #define L_MAX 10000 10 | #define N_MAX 1000 11 | #define MALLOC_MAX (100 * 1024) 12 | 13 | /* Perform several malloc then free. Usa ursage to show memory footprint */ 14 | 15 | /* Random value from 1 to max included */ 16 | static int rnd (int max) { 17 | int i; 18 | double d; 19 | i = rand(); 20 | d = (double)i / ( (double)RAND_MAX + 1.0) * (double)max; 21 | return (int)d; 22 | } 23 | 24 | int main (int argc, char *argv[]) { 25 | 26 | unsigned int seed; 27 | unsigned int n, i, j, size; 28 | void * array[N_MAX]; 29 | 30 | /* Fixed seed */ 31 | seed = 0; 32 | if (argc == 2) { 33 | seed = atoi (argv[1]); 34 | } 35 | if ((int)seed < 0) seed = 0; 36 | srand (seed); 37 | 38 | printf ("%s pid is %d\n", basename(argv[0]), getpid()); 39 | 40 | 41 | if (init_rusage() != RUSAGE_OK) { 42 | perror ("init_rusage"); 43 | exit (1); 44 | } 45 | dump_rusage_str ("Start"); 46 | 47 | for (i = 1; i <= L_MAX; i++) { 48 | n = rnd (N_MAX); 49 | 50 | /* N mallocs of random size */ 51 | size = rnd (MALLOC_MAX); 52 | for (j = 0; j < n; j++) { 53 | array[j] = malloc (size); 54 | if (array[j] == NULL) { 55 | perror ("malloc"); 56 | exit (1); 57 | } 58 | } 59 | 60 | /* Free */ 61 | for (j = 0; j < n; j++) { 62 | free (array[j]); 63 | } 64 | } 65 | 66 | dump_rusage_str ("Stop"); 67 | printf ("Done\n"); 68 | exit (0); 69 | } 70 | 71 | 72 | -------------------------------------------------------------------------------- /man2file/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | EXES := parse_man 4 | 5 | include $(TEMPLATES)/c.mk 6 | 7 | -------------------------------------------------------------------------------- /man2file/parse_man.c: -------------------------------------------------------------------------------- 1 | /* Removes all " Backspace" sequences from stdin to stdout */ 2 | #include 3 | #include 4 | 5 | int main (void) { 6 | 7 | int c1, c2; 8 | 9 | c1 = (char) getchar(); 10 | if ((int)c1 == EOF) exit (0); 11 | 12 | for (;;) { 13 | c2 = (char) getchar(); 14 | 15 | if ( (int)c2 == 8 ) { 16 | /* A backspace. Read next char */ 17 | c1 = (char) getchar(); 18 | } else if ((int)c2 == EOF) { 19 | /* End of file. Done. */ 20 | break; 21 | } else { 22 | /* Other char */ 23 | putchar (c1); 24 | c1 = c2; 25 | } 26 | } 27 | exit(0); 28 | 29 | } 30 | 31 | -------------------------------------------------------------------------------- /mapcode/compare: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ADA=$HOME/ada/usr/mapcode 3 | res=0 4 | echo Encode 5 | while read -r lat lon || [[ -n "$lat" ]]; do 6 | if [ \( -z "$lat" \) -o \( "$lat" = "#" \) ] ; then 7 | continue 8 | fi 9 | 10 | resc=`tmc -c $lat $lon ""` 11 | resa=`${ADA}/t_mapcode -c $lat $lon all | awk ' 12 | ($1 == "=>") { 13 | if ($2 == "AAA") print $3 14 | else print $2 " " $3 15 | } 16 | '` 17 | 18 | if [ "$resa" != "$resc" ] ; then 19 | echo "ERROR: Encoding differs." 1>&2 20 | echo " C: " $resc 1>&2 21 | echo " Ada: " $resa 1>&2 22 | res=1 23 | fi 24 | done < ${ADA}/EncodeOk.txt 25 | 26 | echo Decode 27 | let L=0 28 | while read -r ctx cod lat lon loc glob || [[ -n "$ctx" ]]; do 29 | if [ \( -z "$ctx" \) -o \( "$ctx" = "#" \) ] ; then 30 | continue 31 | fi 32 | resc=`tmc -d $ctx $cod` 33 | resa=`${ADA}/t_mapcode -d $ctx $cod | awk ' 34 | ($1 == "=>") {print $2 " " $3} 35 | '` 36 | 37 | if [ "$resa" != "$resc" ] ; then 38 | echo "ERROR: Decoding differs." 1>&2 39 | echo " C: " $resc 1>&2 40 | echo " Ada: " $resa 1>&2 41 | res=1 42 | fi 43 | 44 | R=$((L % 100)) 45 | if [ $R -eq 0 ] ; then 46 | echo -n "." 47 | fi 48 | let L=$L+1 49 | 50 | done < ${ADA}/DecodeOk.txt 51 | echo 52 | 53 | echo "Done." 54 | exit $res 55 | 56 | -------------------------------------------------------------------------------- /mapcode/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | MAPCODE := $(HOME)/GeoCodes/mapcode/C/mapcodelib 4 | 5 | CCOPT := -I $(MAPCODE) 6 | LDFLAGS := $(MAPCODE)/mapcoder.o -lm 7 | 8 | EXES := tmc 9 | 10 | include $(TEMPLATES)/c.mk 11 | 12 | 13 | -------------------------------------------------------------------------------- /mapcode/tmc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "mapcoder.h" 6 | #include "mapcode_legacy.h" 7 | 8 | static void usage (void) { 9 | fprintf (stderr, "Usage: tmc | \n"); 10 | fprintf (stderr, " ::= -c [ ]\n"); 11 | fprintf (stderr, " ::= -d [ ] \n"); 12 | } 13 | 14 | int main (int argc, char *argv[]) { 15 | 16 | Mapcodes codes; 17 | double lat, lon; 18 | int ctx; 19 | int i, res; 20 | int prec; 21 | char* pmap; 22 | 23 | if (argc < 3) { 24 | fprintf (stderr, "ERROR: Invalid arguments\n"); 25 | usage(); 26 | exit (1); 27 | } 28 | 29 | if (strcmp (argv[1], "-c") == 0 ) { 30 | if ( (argc < 5) || (argc > 6) ) { 31 | fprintf (stderr, "ERROR: Invalid arguments\n"); 32 | usage(); 33 | exit (1); 34 | } 35 | /* Encode */ 36 | if (sscanf (argv[2], "%lf", &lat) != 1) { 37 | fprintf (stderr, "ERROR: Invalid lat %s\n", argv[2]); 38 | exit (1); 39 | } 40 | if (sscanf (argv[3], "%lf", &lon) != 1) { 41 | fprintf (stderr, "ERROR: Invalid lon %s\n", argv[3]); 42 | exit (1); 43 | } 44 | /* Mandatory context, may be empty */ 45 | if (strlen (argv[4]) == 0) { 46 | ctx = 0; 47 | } else { 48 | ctx = getTerritoryCode(argv[4], 0); 49 | if (ctx < 0) { 50 | fprintf (stderr, "ERROR: Invalid context %s\n", argv[4]); 51 | exit (1); 52 | } 53 | } 54 | /* Optional precision */ 55 | if (argc == 5) { 56 | prec = 0; 57 | } else { 58 | if ( (sscanf (argv[5], "%d", &prec) != 1) 59 | || (prec < 0) || (prec > 2) ) { 60 | fprintf (stderr, "ERROR: Invalid precision %s\n", argv[5]); 61 | exit (1); 62 | } 63 | } 64 | 65 | /* Do encode */ 66 | res = encodeLatLonToMapcodes (&codes, lat, lon, ctx, prec); 67 | if (res == 0) { 68 | fprintf (stderr, "ERROR: Cannot encode %s %s in context %s with precision %1d\n", 69 | argv[2], argv[3], argv[4], prec); 70 | exit (1); 71 | } 72 | 73 | for (i = 0; i < codes.count; i++) { 74 | printf ("%s\n", codes.mapcode[i]); 75 | } 76 | 77 | } else if (strcmp (argv[1], "-d") == 0 ) { 78 | /* Decode */ 79 | /* Optional leading context */ 80 | if (argc == 4) { 81 | pmap = argv[3]; 82 | ctx = getTerritoryCode(argv[2], 0); 83 | if (ctx < 0) { 84 | fprintf (stderr, "ERROR: Invalid context %s\n", argv[2]); 85 | exit (1); 86 | } 87 | } else if (argc == 3) { 88 | pmap = argv[2]; 89 | ctx = 0; 90 | } else { 91 | fprintf (stderr, "ERROR: Invalid arguments\n"); 92 | usage(); 93 | exit (1); 94 | } 95 | 96 | /* Do decode */ 97 | res = decodeMapcodeToLatLon (&lat, &lon, pmap, ctx); 98 | if (res != 0) { 99 | fprintf (stderr, "ERROR: Cannot decode %s in context%d\n", pmap, ctx); 100 | exit (1); 101 | } 102 | printf ("%3.9lf %3.9lf\n", lat, lon); 103 | 104 | } else { 105 | fprintf (stderr, "ERROR: Invalid arguments\n"); 106 | usage(); 107 | exit (1); 108 | } 109 | 110 | exit (0); 111 | } 112 | 113 | -------------------------------------------------------------------------------- /mheap/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DINCL := boolean dynlist 4 | 5 | DLIBA := timeval get_line dynlist 6 | 7 | EXES := mheap 8 | 9 | include $(TEMPLATES)/c.mk 10 | 11 | -------------------------------------------------------------------------------- /mu/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DLIBA := vt100 4 | 5 | EXES := mu 6 | LARGS_mu := -lncurses 7 | 8 | include $(TEMPLATES)/c.mk 9 | -------------------------------------------------------------------------------- /mutex/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DINCL := boolean 4 | 5 | LIBS := libmutex 6 | OBJS_libmutex := mutex 7 | 8 | include $(TEMPLATES)/c.mk 9 | 10 | -------------------------------------------------------------------------------- /mutex/mutex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define __USE_GNU 5 | #include "mutex.h" 6 | 7 | /* Create a mutex */ 8 | extern mutex_t mutex_create(void) { 9 | mutex_t mutex; 10 | pthread_mutex_t mut = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP; 11 | 12 | /* Allocate mutex */ 13 | mutex = malloc(sizeof(pthread_mutex_t)); 14 | if (mutex == NULL) { 15 | return NULL; 16 | } 17 | 18 | /* Init mutex */ 19 | *mutex = mut; 20 | 21 | return mutex; 22 | } 23 | 24 | 25 | /* Destroy a mutex */ 26 | /* Returns MUT_LOCKED if the mutex is locked */ 27 | /* Else returns MUT_OK */ 28 | extern int mutex_destroy (mutex_t mutex) { 29 | int res; 30 | 31 | /* Destroy mutex */ 32 | res = pthread_mutex_destroy(mutex); 33 | 34 | switch (res ) { 35 | case 0 : break; 36 | case EBUSY : return MUT_LOCKED; 37 | default : return MUT_ERROR; 38 | } 39 | 40 | /* Free mutex*/ 41 | free (mutex); 42 | return MUT_OK; 43 | } 44 | 45 | 46 | /* Get a mutex */ 47 | /* Returns MUT_DEADLOCK if this thread already owns this mutex */ 48 | /* If wait is set to TRUE, wait for mutex and return MUT_OK */ 49 | /* Else, may return MUT_OK or MUT_LOCKED */ 50 | extern int mutex_lock (mutex_t mutex, boolean wait) { 51 | int res; 52 | 53 | if (wait) { 54 | res = pthread_mutex_lock (mutex); 55 | } else { 56 | res = pthread_mutex_trylock (mutex); 57 | } 58 | 59 | switch (res ) { 60 | case 0 : return MUT_OK; 61 | case EINVAL : return MUT_ERROR; 62 | case EDEADLK : return MUT_DEADLOCK; 63 | case EBUSY : return MUT_LOCKED; 64 | default : return MUT_ERROR; 65 | } 66 | } 67 | 68 | 69 | /* Release a mutex */ 70 | /* Returns MUT_NOTLOCKED if not locked by this thread (or not locked at all) */ 71 | /* Else returns MUT_OK */ 72 | extern int mutex_unlock (mutex_t mutex) { 73 | int res; 74 | 75 | res = pthread_mutex_unlock (mutex); 76 | 77 | switch (res) { 78 | case 0 : return MUT_OK; 79 | case EINVAL : return MUT_ERROR; 80 | case EPERM : return MUT_DEADLOCK; 81 | default : return MUT_ERROR; 82 | } 83 | } 84 | 85 | -------------------------------------------------------------------------------- /mutex/mutex.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "boolean.h" 4 | 5 | #define MUT_OK (0) 6 | #define MUT_LOCKED (-1) 7 | #define MUT_DEADLOCK (-2) 8 | #define MUT_NOTLOCKED (-3) 9 | #define MUT_ERROR (-4) 10 | 11 | typedef pthread_mutex_t *mutex_t; 12 | 13 | /* All calls excep create may raise MUT_ERROR */ 14 | /* If mutex not init or destroyed or... */ 15 | 16 | /* Create a mutex */ 17 | /* Returns NULL if malloc error */ 18 | extern mutex_t mutex_create(void); 19 | 20 | /* Destroy a mutex */ 21 | /* Returns MUT_LOCKED if the mutex is locked */ 22 | /* Else returns MUT_OK */ 23 | extern int mutex_destroy (mutex_t mutex); 24 | 25 | 26 | /* Get a mutex */ 27 | /* Returns MUT_DEADLOCK if this thread already owns this mutex */ 28 | /* If wait is set to TRUE, wait for mutex and return MUT_OK */ 29 | /* Else, may return MUT_OK or MUT_LOCKED */ 30 | extern int mutex_lock (mutex_t mutex, boolean wait); 31 | 32 | /* Release a mutex */ 33 | /* Returns MUT_NOTLOCKED if not locked by this thread (or not locked at all) */ 34 | /* Else returns MUT_OK */ 35 | extern int mutex_unlock (mutex_t mutex); 36 | 37 | -------------------------------------------------------------------------------- /name_of/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DINCL := boolean 4 | DLIBA := socket mutex 5 | 6 | EXES := name_of 7 | 8 | include $(TEMPLATES)/c.mk 9 | 10 | -------------------------------------------------------------------------------- /name_of/name_of.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "boolean.h" 8 | #include "socket.h" 9 | 10 | static void usage (void) { 11 | fprintf (stderr, "ERROR. Only one argument, host name or ip address, accepted\n"); 12 | } 13 | 14 | int main (int argc, char *argv[]) { 15 | 16 | soc_host host; 17 | boolean ip_addr; 18 | int ndots; 19 | int i; 20 | char *p; 21 | char addr[500]; 22 | int res; 23 | 24 | if (argc != 2) { 25 | usage(); 26 | exit(2); 27 | } 28 | 29 | ip_addr = TRUE; 30 | ndots = 0; 31 | 32 | for (i = 0; i < (int)strlen(argv[1]); i++) { 33 | if (argv[1][i] == '.') { 34 | ndots ++; 35 | } else if (! isdigit(argv[1][i])) { 36 | ip_addr = FALSE; 37 | } 38 | } 39 | 40 | if (ip_addr && (ndots != 3)) { 41 | usage(); 42 | } 43 | 44 | 45 | if (ip_addr) { 46 | strcpy (addr, argv[1]); 47 | p = addr; 48 | ndots = 0; 49 | for (i = 0; i < (int)strlen(argv[1]); i++) { 50 | if (addr[i] == '.') { 51 | addr[i] = '\0'; 52 | host.bytes[ndots] = atoi(p); 53 | p = &(addr[i+1]); 54 | ndots++; 55 | } 56 | } 57 | host.bytes[ndots] = atoi(p); 58 | 59 | printf("Looking for ip addr: "); 60 | for (i = 0; i <= 3; i++) { 61 | printf("%d", (int)host.bytes[i]); 62 | if (i != 3) { 63 | printf("."); 64 | } 65 | } 66 | printf("\n"); 67 | res = soc_host_name_of (&host, addr, sizeof(addr)); 68 | if (res != SOC_OK) { 69 | fprintf (stderr, "soc_host_name_of -> %d\n", res); 70 | exit (1); 71 | } else { 72 | printf ("Got: %s\n", addr); 73 | } 74 | } else { 75 | printf("Looking for host name: %s\n", argv[1]); 76 | res = soc_host_of (argv[1], &host); 77 | if (res != SOC_OK) { 78 | fprintf (stderr, "soc_host_of -> %d\n", res); 79 | exit (1); 80 | } else { 81 | printf("Got: "); 82 | for (i = 0; i <= 3; i++) { 83 | printf("%d", (int)host.bytes[i]); 84 | if (i != 3) { 85 | printf("."); 86 | } 87 | } 88 | printf("\n"); 89 | } 90 | 91 | } 92 | exit (0); 93 | } 94 | 95 | 96 | -------------------------------------------------------------------------------- /pause/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | EXES := pause 4 | 5 | include $(TEMPLATES)/c.mk 6 | 7 | -------------------------------------------------------------------------------- /pause/pause.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main (void) { 5 | (void) pause(); 6 | exit(0); 7 | } 8 | -------------------------------------------------------------------------------- /pcre/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | EXES := tpcre tpcre2 tposix2pcre2 4 | 5 | # PCRE OK 6 | LARGS_tpcre := -lpcreposix -lpcre 7 | 8 | # PCRE2 NOK 9 | # On Ubuntu, erroneously links to the standard POSIX library instead of 10 | # pcre2-posix, which leads tpcre2 to core in regfree after success, and to 11 | # compile OK erroneous regex 't(', then regexec fails on error "No match" 12 | LARGS_tpcre2 := -lpcre2-posix -lpcre2-8 13 | 14 | # POSIX2PCRE OK 15 | LARGS_tposix2pcre2 := -lposix2pcre -lpcre2-posix -lpcre2-8 16 | 17 | include $(TEMPLATES)/c.mk 18 | 19 | -------------------------------------------------------------------------------- /pcre/tpcre.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | static void usage (char *name) { 8 | fprintf (stderr, "Usage: %s { [ ] }\n", name); 9 | } 10 | 11 | static void print_match (regmatch_t match) { 12 | printf ("Match at %d-%d\n", match.rm_so, match.rm_eo - 1); 13 | } 14 | 15 | #define MAX_MATCHES 100 16 | int main (int argc, char *argv[]) { 17 | 18 | int i, j, n, res; 19 | regex_t regex; 20 | char buffer[1024]; 21 | regmatch_t matches[MAX_MATCHES]; 22 | 23 | /* At least one argument, -h | --help | */ 24 | if (argc < 2) { 25 | usage (argv[0]); 26 | exit (1); 27 | } 28 | 29 | /* Help */ 30 | if ( (strcmp (argv[1], "-h") == 0) || (strcmp (argv[1], "--help") == 0) ) { 31 | usage (argv[0]); 32 | exit (0); 33 | } 34 | /* Show version */ 35 | if ( (strcmp (argv[1], "-v") == 0) || (strcmp (argv[1], "--version") == 0) ) { 36 | printf ("Pcre version is %s\n", pcre_version()); 37 | exit (0); 38 | } 39 | 40 | /* Compile regex */ 41 | res = regcomp (®ex, argv[1], 0); 42 | if (res != 0) { 43 | (void) regerror (res, ®ex, buffer, sizeof(buffer)); 44 | fprintf (stderr, "ERROR: Compilation has failed with error: %s\n", 45 | buffer); 46 | exit (1); 47 | } 48 | 49 | /* Check strings */ 50 | for (i = 3; i <= argc; i++) { 51 | /* Compile */ 52 | res = regexec (®ex, argv[i-1], MAX_MATCHES, matches, 0); 53 | if (res == REG_NOMATCH) { 54 | printf ("No match\n"); 55 | continue; 56 | } 57 | if (res != 0) { 58 | (void) regerror (res, ®ex, buffer, sizeof(buffer)); 59 | fprintf (stderr, "ERROR: Execution has failed with error: %s\n", 60 | buffer); 61 | exit (1); 62 | } 63 | /* Print result */ 64 | print_match (matches[0]); 65 | 66 | /* Count matching substrings */ 67 | n = 0; 68 | for (j = MAX_MATCHES - 1; j >= 0; j--) { 69 | if (matches[j].rm_so != -1) { 70 | n = j; 71 | break; 72 | } 73 | } 74 | 75 | /* Print matching substrings */ 76 | for (j = 1; j <= n; j++) { 77 | print_match (matches[j]); 78 | } 79 | } 80 | 81 | /* Cleanup */ 82 | regfree (®ex); 83 | 84 | /* Done */ 85 | exit (0); 86 | } 87 | 88 | -------------------------------------------------------------------------------- /pcre/tpcre2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | #define PCRE2_CODE_UNIT_WIDTH 8 7 | #include 8 | 9 | static void usage (char *name) { 10 | fprintf (stderr, "Usage: %s { [ ] }\n", name); 11 | } 12 | 13 | static void print_match (regmatch_t match) { 14 | printf ("Match at %d-%d\n", match.rm_so, match.rm_eo - 1); 15 | } 16 | 17 | #define MAX_MATCHES 100 18 | int main (int argc, char *argv[]) { 19 | 20 | int i, j, n, res; 21 | regex_t regex; 22 | char buffer[1024]; 23 | regmatch_t matches[MAX_MATCHES]; 24 | 25 | /* At least one argument, -h | --help | */ 26 | if (argc < 2) { 27 | usage (argv[0]); 28 | exit (1); 29 | } 30 | 31 | /* Help */ 32 | if ( (strcmp (argv[1], "-h") == 0) || (strcmp (argv[1], "--help") == 0) ) { 33 | usage (argv[0]); 34 | exit (0); 35 | } 36 | /* Show version */ 37 | if ( (strcmp (argv[1], "-v") == 0) || (strcmp (argv[1], "--version") == 0) ) { 38 | res = pcre2_config (PCRE2_CONFIG_VERSION, buffer); 39 | printf ("Pcre version is %s\n", buffer); 40 | exit (0); 41 | } 42 | 43 | /* Compile regex */ 44 | res = regcomp (®ex, argv[1], 0); 45 | if (res != 0) { 46 | (void) regerror (res, ®ex, buffer, sizeof(buffer)); 47 | fprintf (stderr, "ERROR: Compilation has failed with error: %s\n", 48 | buffer); 49 | exit (1); 50 | } 51 | 52 | /* Check strings */ 53 | for (i = 3; i <= argc; i++) { 54 | /* Compile */ 55 | res = regexec (®ex, argv[i-1], MAX_MATCHES, matches, 0); 56 | if (res == REG_NOMATCH) { 57 | printf ("No match\n"); 58 | continue; 59 | } 60 | if (res != 0) { 61 | (void) regerror (res, ®ex, buffer, sizeof(buffer)); 62 | fprintf (stderr, "ERROR: Execution has failed with error: %s\n", 63 | buffer); 64 | exit (1); 65 | } 66 | /* Print result */ 67 | print_match (matches[0]); 68 | 69 | /* Count matching substrings */ 70 | n = 0; 71 | for (j = MAX_MATCHES - 1; j >= 0; j--) { 72 | if (matches[j].rm_so != -1) { 73 | n = j; 74 | break; 75 | } 76 | } 77 | 78 | /* Print matching substrings */ 79 | for (j = 1; j <= n; j++) { 80 | print_match (matches[j]); 81 | } 82 | } 83 | 84 | /* Cleanup */ 85 | regfree (®ex); 86 | 87 | /* Done */ 88 | exit (0); 89 | } 90 | 91 | -------------------------------------------------------------------------------- /pcre/tposix2pcre2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | static void usage (char *name) { 8 | fprintf (stderr, "Usage: %s { [ ] }\n", name); 9 | } 10 | 11 | static void print_match (regmatch_t match) { 12 | printf ("Match at %d-%d\n", match.rm_so, match.rm_eo - 1); 13 | } 14 | 15 | #define MAX_MATCHES 100 16 | int main (int argc, char *argv[]) { 17 | 18 | int i, j, n, res; 19 | regex_t regex; 20 | char buffer[1024]; 21 | const char *pchar; 22 | regmatch_t matches[MAX_MATCHES]; 23 | 24 | /* At least one argument, -h | --help | */ 25 | if (argc < 2) { 26 | usage (argv[0]); 27 | exit (1); 28 | } 29 | 30 | /* Help */ 31 | if ( (strcmp (argv[1], "-h") == 0) || (strcmp (argv[1], "--help") == 0) ) { 32 | usage (argv[0]); 33 | exit (0); 34 | } 35 | /* Show version */ 36 | if ( (strcmp (argv[1], "-v") == 0) || (strcmp (argv[1], "--version") == 0) ) { 37 | pchar = pcre_version (); 38 | printf ("Pcre version is %s\n", pchar); 39 | exit (0); 40 | } 41 | 42 | /* Compile regex */ 43 | res = posix2pcre_regcomp (®ex, argv[1], 0); 44 | if (res != 0) { 45 | (void) posix2pcre_regerror (res, ®ex, buffer, sizeof(buffer)); 46 | fprintf (stderr, "ERROR: Compilation has failed with error: %s\n", 47 | buffer); 48 | exit (1); 49 | } 50 | 51 | /* Check strings */ 52 | for (i = 3; i <= argc; i++) { 53 | /* Compile */ 54 | res = posix2pcre_regexec (®ex, argv[i-1], MAX_MATCHES, matches, 0); 55 | if (res == REG_NOMATCH) { 56 | printf ("No match\n"); 57 | continue; 58 | } 59 | if (res != 0) { 60 | (void) posix2pcre_regerror (res, ®ex, buffer, sizeof(buffer)); 61 | fprintf (stderr, "ERROR: Execution has failed with error: %s\n", 62 | buffer); 63 | exit (1); 64 | } 65 | /* Print result */ 66 | print_match (matches[0]); 67 | 68 | /* Count matching substrings */ 69 | n = 0; 70 | for (j = MAX_MATCHES - 1; j >= 0; j--) { 71 | if (matches[j].rm_so != -1) { 72 | n = j; 73 | break; 74 | } 75 | } 76 | 77 | /* Print matching substrings */ 78 | for (j = 1; j <= n; j++) { 79 | print_match (matches[j]); 80 | } 81 | } 82 | 83 | /* Cleanup */ 84 | posix2pcre_regfree (®ex); 85 | 86 | /* Done */ 87 | exit (0); 88 | } 89 | 90 | -------------------------------------------------------------------------------- /pcrypt/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | EXES := pcrypt 4 | 5 | LARGS_pcrypt := -lcrypt 6 | 7 | include $(TEMPLATES)/c.mk 8 | 9 | -------------------------------------------------------------------------------- /pcrypt/pcrypt.c: -------------------------------------------------------------------------------- 1 | #define _XOPEN_SOURCE 2 | #include 3 | #undef _XOPEN_SOURCE 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | /* Password encryption */ 11 | 12 | #define Usage() fprintf(stderr, "Usage: %s <2_digits_key> \n", \ 13 | basename(argv[0])) 14 | 15 | int main (int argc, char *argv[]) { 16 | 17 | if (argc != 3) { 18 | Usage(); 19 | exit(1); 20 | } 21 | 22 | if (strlen(argv[1]) != 2) { 23 | Usage(); 24 | exit(1); 25 | } 26 | 27 | printf ("Salt: %s and Key: %s -> %s\n", 28 | argv[1], argv[2], 29 | crypt (argv[2], argv[1])); 30 | 31 | exit(0); 32 | } 33 | 34 | -------------------------------------------------------------------------------- /putvar/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | EXES := putvar 4 | 5 | include $(TEMPLATES)/c.mk 6 | 7 | -------------------------------------------------------------------------------- /putvar/putvar.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* Get freom ENV the variables provided as argument */ 5 | 6 | int main (int argc, char *argv[]) { 7 | 8 | int i; 9 | char *p; 10 | 11 | 12 | for (i = 1; i < argc; i++) { 13 | p = getenv (argv[i]); 14 | if (p == NULL) { 15 | printf ("%s is not set\n", argv[i]); 16 | } else { 17 | printf ("%s is set to %s\n", argv[i], p); 18 | } 19 | } 20 | 21 | exit (0); 22 | } 23 | 24 | -------------------------------------------------------------------------------- /rusage/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | LIBS := librusage 4 | OBJS_librusage := rusage 5 | 6 | EXES := anal_rusage t_rusage 7 | LIBS_anal_rusage := librusage 8 | LIBS_t_rusage := librusage 9 | 10 | include $(TEMPLATES)/c.mk 11 | 12 | -------------------------------------------------------------------------------- /rusage/rusage.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | #include "rusage.h" 16 | 17 | /* Is the dump_rusage function already installed */ 18 | static int rusage_installed = 0; 19 | /* File where file_block are written */ 20 | static FILE *rusage_file = (FILE*) NULL; 21 | 22 | 23 | /* Handler of RUSAGE_SIG signal */ 24 | #ifdef __STDC__ 25 | /*ARGSUSED*/ 26 | static void signal_rusage (int sig) 27 | #else 28 | static void signal_rusage (sig) 29 | int sig; 30 | #endif 31 | { 32 | char str[50]; 33 | sprintf (str, "Signal %d", sig); 34 | dump_rusage_str(str); 35 | } 36 | 37 | /* Inititialises the dump_rusage function */ 38 | /* Returns : RUSAGE_OK if success; RUSAGE_ERROR otherwise */ 39 | #ifdef __STDC__ 40 | int init_rusage(void) 41 | #else 42 | int init_rusage() 43 | #endif /* __STDC__ */ 44 | { 45 | 46 | /* Hook dump_rusage signal handler on RUSAGE_SIG signal */ 47 | if (signal (RUSAGE_SIG, signal_rusage) == SIG_ERR) { 48 | return (RUSAGE_ERROR); 49 | } else { 50 | return (RUSAGE_OK); 51 | } 52 | 53 | } 54 | 55 | #ifdef __STDC__ 56 | static int open_file(void) 57 | #else 58 | static int open_file() 59 | #endif /* __STDC__ */ 60 | { 61 | /* Pid image on 5 digits */ 62 | pid_t my_pid; 63 | 64 | char hostname[MAXHOSTNAMELEN]; 65 | char file_name [255]; 66 | 67 | if (rusage_installed != 0) return rusage_installed; 68 | 69 | /* Get pid */ 70 | my_pid = getpid(); 71 | 72 | /* Build file name : "rusage_HOSTNAME_PID" */ 73 | if (gethostname(hostname, sizeof(hostname)) != 0) { 74 | return (RUSAGE_ERROR); 75 | } 76 | (void) sprintf (file_name, "rusage_%s_%05d", hostname, my_pid); 77 | 78 | /* Open file */ 79 | rusage_file = fopen(file_name, "w"); 80 | if (rusage_file == (FILE*)NULL) { 81 | /* Failed */ 82 | rusage_installed = -1; 83 | } else { 84 | /* Done OK */ 85 | rusage_installed = 1; 86 | } 87 | return rusage_installed; 88 | } 89 | 90 | #ifdef __STDC__ 91 | /*ARGSUSED*/ 92 | void dump_rusage (void) 93 | #else 94 | void dump_rusage () 95 | #endif 96 | { 97 | dump_rusage_str(NULL); 98 | } 99 | 100 | #ifdef __STDC__ 101 | /*ARGSUSED*/ 102 | void dump_rusage_str (const char *str) 103 | #else 104 | void dump_rusage_str (str) 105 | char *str; 106 | #endif 107 | { 108 | 109 | file_block block; 110 | 111 | /* One check on the status of the file on normal execution (file open) */ 112 | if (open_file() != 1) { 113 | /* Failure in opening file. No action. */ 114 | return; 115 | } 116 | 117 | /* Get time and rusage */ 118 | gettimeofday (&block.time, NULL); 119 | getrusage(RUSAGE_SELF, &block.usage); 120 | block.pr_size = 0; 121 | 122 | if (str == NULL) { 123 | block.msg[0] = '\0'; 124 | } else { 125 | strncpy (block.msg, str, RU_USER_MSG_SIZE-1); 126 | block.msg[RU_USER_MSG_SIZE-1] = '\0'; 127 | } 128 | 129 | /* Write file_block on file */ 130 | (void) fwrite ((void*)&block, sizeof(file_block), 1, rusage_file); 131 | (void) fflush (rusage_file); 132 | } 133 | 134 | -------------------------------------------------------------------------------- /rusage/rusage.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __RUSAGE_H__ 3 | #define __RUSAGE_H__ 1 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | /* Signal which makes the rusage to be dumped */ 10 | # define RUSAGE_SIG SIGXFSZ 11 | 12 | /* Result */ 13 | #define RUSAGE_OK 0 14 | #define RUSAGE_ERROR -1 15 | 16 | #ifdef __STDC__ 17 | 18 | /* First call to initialise the rusage procedure */ 19 | /* Need to be called once before triggering dump_rusage with signal */ 20 | /* RUSAGE_SIG */ 21 | /* Returns RUSAGE_OK, or RUSAGE_ERROR. */ 22 | extern int init_rusage(void); 23 | 24 | /* Call to dump a record, possibly with a title */ 25 | extern void dump_rusage(void); 26 | extern void dump_rusage_str(const char *); 27 | 28 | #else /* !__STDC__ */ 29 | 30 | extern int init_rusage(); 31 | extern void dump_rusage(); 32 | extern void dump_rusage_str(); 33 | 34 | #endif /* __STDC__ */ 35 | 36 | /* Structure dumped in the file "rusage_HOST_PID" */ 37 | /* At each time the RUSAGE_SIG signal is received or dump_rusage is called */ 38 | /* and to be read by anal_rusage program */ 39 | 40 | #define RU_USER_MSG_SIZE 128 41 | 42 | typedef struct { 43 | struct timeval time; 44 | struct rusage usage; 45 | long pr_size; 46 | char msg[RU_USER_MSG_SIZE]; 47 | } file_block; 48 | 49 | #endif /* __RUSAGE_H__ */ 50 | 51 | -------------------------------------------------------------------------------- /rusage/t_rusage.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "rusage.h" 6 | 7 | int main (void) { 8 | 9 | int i; 10 | void __attribute__((unused)) *p; 11 | /* 12 | if (init_rusage() != RUSAGE_OK) { 13 | fprintf (stderr, "Cannot init rusage\n"); 14 | exit (1); 15 | } 16 | */ 17 | 18 | for (;;) { 19 | dump_rusage_str ("Call"); 20 | for (i=1; i< 10000; i++) 21 | p = malloc(1 * 1024 * 1024); 22 | (void) sleep (1) ; 23 | } 24 | 25 | } 26 | 27 | -------------------------------------------------------------------------------- /sem_util/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DINCL := boolean 4 | 5 | CCOPT := -O -D$(HOST) $(CCOPT) 6 | 7 | LIBS := libsem_util 8 | OBJS_libsem_util := sem_util 9 | 10 | include $(TEMPLATES)/c.mk 11 | 12 | -------------------------------------------------------------------------------- /sem_util/sem_util.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "sem_util.h" 8 | 9 | 10 | union semun { 11 | int val; /* value for SETVAL */ 12 | struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ 13 | u_short *array; /* array for GETALL & SETALL */ 14 | #ifdef linux 15 | struct seminfo *__buf; /* buffer for IPC_INFO */ 16 | #endif 17 | }; 18 | 19 | int get_sem_id (int sem_key) { 20 | int sem_id; 21 | 22 | sem_id = semget ( (key_t)sem_key, 1, 0666); 23 | if (sem_id == -1) { 24 | perror ("get_sem_id.semget"); 25 | return (ERR); 26 | } 27 | 28 | return (sem_id); 29 | } 30 | 31 | t_result create_sem_key (int sem_key, int *p_sem_id) { 32 | int sem_id; 33 | union semun arg1; 34 | 35 | /* creation of the semaphore associated with the key key_sem */ 36 | sem_id = semget ( (key_t)sem_key, 1, IPC_CREAT | 0666); 37 | if (sem_id == -1) { 38 | perror ("create_sem_key.semget"); 39 | return (ERR); 40 | } 41 | 42 | /* Out value sem_id */ 43 | if (p_sem_id != NULL) *p_sem_id = sem_id; 44 | 45 | /* initialisation of the semaphore number 0 associated */ 46 | /* with the id number semid */ 47 | arg1.val = 1; 48 | if (semctl (sem_id, 0 , SETVAL , arg1) == -1 ) { 49 | perror ("create_sem_key.semctl"); 50 | return (ERR); 51 | } 52 | 53 | return (OK); 54 | } 55 | 56 | 57 | t_result delete_sem_id (int sem_id) { 58 | /* deletion of the semaphore number 0 associated */ 59 | /* with the id number semid */ 60 | if (semctl (sem_id, 0 , IPC_RMID , 1) == -1 ) { 61 | perror ("delete_sem_id.semctl"); 62 | return (ERR); 63 | } 64 | 65 | return (OK); 66 | } 67 | 68 | 69 | t_result delete_sem_key (int sem_key) { 70 | int sem_id; 71 | /* research of the id number associated with the key: key_sem */ 72 | sem_id = get_sem_id (sem_key); 73 | if (sem_id == ERR) return (ERR); 74 | 75 | return (delete_sem_id(sem_id)); 76 | } 77 | 78 | 79 | static t_result incr_decr_sem_id (int sem_id, boolean incr, boolean undo) { 80 | struct sembuf sops; 81 | int res; 82 | 83 | sops.sem_num = (short) 0; /* semaphore number 0 */ 84 | sops.sem_op = (short) (incr ? 1 : -1); /* semaphore operation */ 85 | /* operation flags : process lock until the semaphore is zero */ 86 | sops.sem_flg = (undo ? SEM_UNDO : 0); 87 | 88 | do { 89 | errno = 0; 90 | res = semop (sem_id, (struct sembuf *)(&sops), 1); 91 | if ( (res == -1) && (errno != EINTR) ) { 92 | perror ("decr_sem_id.semctl"); 93 | return (ERR); 94 | } 95 | } while (res == -1); 96 | 97 | return (OK); 98 | } 99 | 100 | t_result decr_sem_id (int sem_id, boolean undo) { 101 | 102 | return incr_decr_sem_id (sem_id, FALSE, undo); 103 | } 104 | 105 | 106 | t_result decr_sem_key (int sem_key, boolean undo) { 107 | int sem_id; 108 | 109 | sem_id = get_sem_id (sem_key); 110 | if (sem_id == ERR) return (ERR); 111 | 112 | return decr_sem_id (sem_id, undo); 113 | } 114 | 115 | 116 | 117 | t_result incr_sem_id (int sem_id, boolean undo) { 118 | return incr_decr_sem_id (sem_id, TRUE, undo); 119 | } 120 | 121 | t_result incr_sem_key (int sem_key, boolean undo) { 122 | int sem_id; 123 | 124 | sem_id = get_sem_id (sem_key); 125 | if (sem_id == -1) return (ERR); 126 | 127 | return incr_sem_id(sem_id, undo); 128 | } 129 | -------------------------------------------------------------------------------- /sem_util/sem_util.h: -------------------------------------------------------------------------------- 1 | #include "boolean.h" 2 | 3 | /* Results of calls */ 4 | #define OK 0 5 | #define ERR -1 6 | 7 | #define t_result int 8 | 9 | /* Creates a semaphore associated with the given key */ 10 | /* The out value sem_id is set, if p_sem_id != NULL for furhter use */ 11 | t_result create_sem_key (int sem_key, int *p_sem_id); 12 | 13 | /* Id of the semaphore associated with the key, or ERR */ 14 | /* The sem must have been created */ 15 | int get_sem_id (int sem_key); 16 | 17 | /* The calls with id are faster the the calls with the key */ 18 | t_result delete_sem_id (int sem_id); 19 | t_result delete_sem_key (int sem_key); 20 | 21 | /* decrements the semaphore (try to get (blocking) ) */ 22 | t_result decr_sem_id (int sem_id, boolean undo); 23 | t_result decr_sem_key (int sem_key, boolean undo); 24 | 25 | /* increments (release) the semaphore */ 26 | t_result incr_sem_id (int sem_id, boolean undo); 27 | t_result incr_sem_key (int sem_key, boolean undo); 28 | 29 | -------------------------------------------------------------------------------- /semctl/Semctl: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DIR=. 4 | 5 | if [ `uname` != Linux ] ; then 6 | sem_list=`ipcs -s | awk ' ($1 == "s") {print $2} '` 7 | else 8 | sem_list=`ipcs -s | awk ' { if ($2 == int($2)) { print $2} }'` 9 | fi 10 | 11 | if [ "$1" = "-a" ] ; then 12 | shift 13 | for sem in $sem_list ; do 14 | $DIR/semctl -i $sem $* 15 | echo 16 | done 17 | elif [ "$1" = "-b" ] ; then 18 | shift 19 | for sem in $sem_list ; do 20 | $DIR/semctl -i $sem s 21 | res=$? 22 | if [ $res -eq 1 ] ; then 23 | $DIR/semctl -i $sem b 24 | echo 25 | fi 26 | done 27 | elif [ \( "$1" = "-h" \) -o \( "$1" = "" \) ] ; then 28 | echo "Usage: `basename $0` " 29 | echo " ::= -a | -b | " 30 | echo " -a = all sems -b = all blocked" 31 | echo "" 32 | echo " ::= [ ]" 33 | echo " ::= -i | -k " 34 | echo " ::= | b | s" 35 | echo " b = blocked nums of sem" 36 | echo " s = silent (exit 0 or 1 if some num blocked)" 37 | else 38 | $DIR/semctl $* 39 | fi 40 | 41 | -------------------------------------------------------------------------------- /semctl/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | #-Wunreach fails ctype.h 3 | CCOPT_Linux ?= -pedantic -Wall -W -Wpointer-arith \ 4 | -Wbad-function-cast -Wcast-qual -Wcast-align -Wwrite-strings \ 5 | -Wsign-compare -Wstrict-prototypes -Wmissing-prototypes \ 6 | -Wmissing-declarations -Wmissing-noreturn -Winline \ 7 | -Wfloat-equal -Wundef 8 | 9 | DINCL := boolean 10 | DLIBA := timeval sem_util 11 | 12 | CCOPT := -O $(CCOPT) 13 | 14 | EXES := semget semctl 15 | 16 | include $(TEMPLATES)/c.mk 17 | 18 | -------------------------------------------------------------------------------- /semctl/semget.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "sem_util.h" 7 | #include "timeval.h" 8 | 9 | #define KEY 0x11111 10 | 11 | int main (void) { 12 | 13 | int id; 14 | int wait; 15 | timeout_t timeout; 16 | 17 | printf ("My pid is %d\n", getpid()); 18 | 19 | id = get_sem_id (KEY); 20 | 21 | if (id != ERR) { 22 | printf ("Sem %d got, id %d\n", KEY, id); 23 | wait = 0; 24 | } else { 25 | fflush(stderr); 26 | if (create_sem_key (KEY, &id) == OK) { 27 | printf ("Sem %d created, id %d\n", KEY, id); 28 | } else { 29 | printf ("sem %d creation failure. Errno %d\n", KEY, errno); 30 | exit (1); 31 | } 32 | wait = 1; 33 | } 34 | 35 | if (decr_sem_id(id, FALSE) != OK) { 36 | printf ("Sem %d id %d decrementation failure. Errno %d\n", KEY, id, errno); 37 | } 38 | 39 | if (wait) { 40 | for (;;) { 41 | timeout.tv_sec = 10; 42 | timeout.tv_usec = 0; 43 | delay (&timeout); 44 | } 45 | } 46 | exit(0); 47 | } 48 | 49 | -------------------------------------------------------------------------------- /shm/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DINCL := boolean 4 | DLIBA := sig_util 5 | 6 | EXES := shm 7 | 8 | include $(TEMPLATES)/c.mk 9 | 10 | -------------------------------------------------------------------------------- /sig_util/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DINCL := boolean 4 | DLIBA := timeval 5 | 6 | LIBS := libsig_util 7 | EXES := t_pause t_sig 8 | 9 | OBJS_libsig_util := sig_util 10 | 11 | LIBS_t_pause := libsig_util 12 | LIBS_t_sig := libsig_util 13 | 14 | include $(TEMPLATES)/c.mk 15 | 16 | -------------------------------------------------------------------------------- /sig_util/sig_util.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "sig_util.h" 8 | 9 | t_result set_handler (int sig_num, void (*sig_handler)(int), 10 | void (**old_handler)(int)) { 11 | void (*loc_old_handler)(int); 12 | 13 | 14 | loc_old_handler = signal (sig_num, sig_handler); 15 | if ( (loc_old_handler != SIG_ERR) && (old_handler != NULL) ) { 16 | *old_handler = loc_old_handler; 17 | } 18 | 19 | if (loc_old_handler != SIG_ERR) { 20 | return (OK); 21 | } else { 22 | perror ("set_handler.signal"); 23 | return (ERR); 24 | } 25 | } 26 | 27 | 28 | t_result arm_timer (int timer, t_time sec, t_time usec, boolean repeat) { 29 | struct itimerval val; 30 | 31 | val.it_value.tv_sec = sec; 32 | val.it_value.tv_usec = usec; 33 | 34 | /* set interval; if not repeat, set it to 0 */ 35 | if (repeat) { 36 | val.it_interval.tv_sec = sec; 37 | val.it_interval.tv_usec = usec; 38 | } else { 39 | val.it_interval.tv_sec = 0; 40 | val.it_interval.tv_usec = 0; 41 | } 42 | 43 | 44 | if (setitimer (timer, &val, NULL) == -1) { 45 | perror ("arm.setitimer"); 46 | return (ERR); 47 | } else { 48 | return (OK); 49 | } 50 | } 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /sig_util/sig_util.h: -------------------------------------------------------------------------------- 1 | #include "boolean.h" 2 | 3 | /* Results of calls */ 4 | #define OK 0 5 | #define ERR -1 6 | 7 | #define t_time int 8 | #define t_result int 9 | 10 | 11 | /* To set an signal handler to a signal. */ 12 | /* or to restore default handler */ 13 | /* See signal.h for sig_num possible values */ 14 | /* SIG_DFL and SIG_IGN can be used for default or ignore handlers */ 15 | /* Old_handler may be NULL if of no interest */ 16 | 17 | t_result set_handler (int sig_num, void (*sig_handler)(int), 18 | void (**old_handler)(int) ); 19 | 20 | /* To arm one or disarm of the 3 timers. */ 21 | /* See sys/time.h for the list of timers */ 22 | /* sec and usec specify the interval (delay between 2 signals) */ 23 | /* If the delay is <= 0 then the timer is desabled */ 24 | /* if not repeat then only one signal will be generated after delay */ 25 | /* if repeat then a signal will be generated repetitively */ 26 | 27 | t_result arm_timer (int timer, t_time sec, t_time usec, boolean repeat); 28 | 29 | -------------------------------------------------------------------------------- /sig_util/t_pause.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "sig_util.h" 8 | 9 | /* handle and ump signals ALRM, USR1 and USR2 */ 10 | 11 | #define ALRM_S 000005 12 | #define ALRM_U 000000 13 | 14 | extern void sigpause (int mask); 15 | 16 | static void handler_sigalrm(int sig); 17 | static void handler_sigusr1(int sig); 18 | static void handler_sigusr2(int sig); 19 | 20 | int main(void) { 21 | sigset_t mask, oldmask; 22 | 23 | 24 | 25 | printf ("My pid is %d\n", getpid()); 26 | printf ( 27 | "Signal managed : SIGTALRM(intern), SIGUSR1(30), SIGUSR2(31)\n"); 28 | 29 | 30 | set_handler (SIGALRM, handler_sigalrm, NULL); 31 | set_handler (SIGUSR1, handler_sigusr1, NULL); 32 | set_handler (SIGUSR2, handler_sigusr2, NULL); 33 | 34 | printf ("Start timer\n"); 35 | arm_timer (ITIMER_REAL, (long)ALRM_S, (long)ALRM_U, 1); 36 | 37 | sigemptyset (&mask); 38 | sigaddset (&mask, SIGALRM|SIGUSR1); 39 | sigprocmask (SIG_BLOCK, &mask, &oldmask); 40 | sigsuspend(&oldmask); 41 | sigprocmask (SIG_UNBLOCK, &mask, NULL); 42 | printf ("Done.\n"); 43 | exit(0); 44 | } 45 | 46 | static void handler_sigalrm (int sig) { 47 | printf (" SIGALRM...%3d\n", sig); 48 | } 49 | 50 | static void handler_sigusr1 (int sig) { 51 | printf (" SIGUSR1...%3d\n", sig); 52 | } 53 | 54 | static void handler_sigusr2 (int sig) { 55 | printf (" SIGUSR2...%3d\n", sig); 56 | } 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /sig_util/t_sig.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "sig_util.h" 7 | #include "timeval.h" 8 | 9 | /* Catch and show signals TERM and INT */ 10 | 11 | static void sig_handler(int sig); 12 | 13 | int main(void) { 14 | timeout_t timeout; 15 | 16 | set_handler (SIGTERM, sig_handler, NULL); 17 | set_handler (SIGINT, sig_handler, NULL); 18 | timeout.tv_sec = 5; 19 | timeout.tv_usec = 0; 20 | 21 | for (;;) { 22 | printf ("Running\n"); 23 | delay (&timeout); 24 | } 25 | 26 | } 27 | 28 | static void sig_handler(int sig) { 29 | printf (" signal received : %3d\n", sig); 30 | } 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /socket/makefile: -------------------------------------------------------------------------------- 1 | # Compile socket without depend to wait_evt 2 | # (evt_fd_set always returns False) 3 | include $(HOME)/Makefiles/common.mk 4 | 5 | DINCL := boolean 6 | DLIBA := mutex 7 | 8 | FILES2LINK := socket.h socket_afux.h socket_prv.h socket_afux.c socket_net.h \ 9 | socket.c 10 | LINKFROM := $(HOME)/ada/c 11 | 12 | LIBS := libsocket 13 | 14 | OBJS_libsocket := socket socket_afux 15 | CARGS_socket := -DSOCKET_NO_EVT -DSOCKET_MUTEX 16 | 17 | include $(TEMPLATES)/c.mk 18 | 19 | -------------------------------------------------------------------------------- /socket_evt/makefile: -------------------------------------------------------------------------------- 1 | # Compile socket with depend to wait_evt 2 | include $(HOME)/Makefiles/common.mk 3 | 4 | DINCL := boolean 5 | DLIBA := timeval wait_evt 6 | 7 | FILES2LINK := socket.h socket_afux.h socket_prv.h socket_afux.c socket_net.h \ 8 | socket.c 9 | LINKFROM := $(HOME)/ada/c 10 | 11 | LIBS := libsocket_evt 12 | 13 | OBJS_libsocket_evt := socket socket_afux 14 | 15 | include $(TEMPLATES)/c.mk 16 | 17 | -------------------------------------------------------------------------------- /status/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | EXES := status 4 | 5 | include $(TEMPLATES)/c.mk 6 | 7 | -------------------------------------------------------------------------------- /status/status.c: -------------------------------------------------------------------------------- 1 | /* Check if target file: $n is up to date comparing to source files: */ 2 | /* $1, $2 .. $n-1. This is: target file exists and is newer that sources. */ 3 | /* exit 0 --> $n file is ok (newer than all sources) */ 4 | /* exit 1 --> $n file is older than some sources or does not exist */ 5 | /* exit 2 --> Error: cannot read some source files */ 6 | /* exit 3 --> Argument or internal error */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #define EXIT_OK 0 18 | #define EXIT_NOK 1 19 | #define EXIT_SRC_NOT_FOUND 2 20 | #define EXIT_INTERNAL_ERROR 3 21 | 22 | 23 | 24 | static char *prog_name (char *prog_path) { 25 | char *p = strrchr(prog_path, '/'); 26 | if (p == NULL) p = prog_path; 27 | else p++; 28 | return (p); 29 | } 30 | 31 | 32 | int main (int argc, char *argv[]) { 33 | 34 | struct stat bs, br; 35 | int result; 36 | int i; 37 | 38 | 39 | /* Check arguments */ 40 | if (argc < 3) { 41 | fprintf (stderr, "SYNTAX ERROR. Usage : %s { } \n", 42 | prog_name(argv[0])); 43 | exit (EXIT_INTERNAL_ERROR); 44 | } 45 | 46 | /* Check that target file exists and get its modif date */ 47 | result = EXIT_OK; 48 | if (stat (argv[argc-1], &br) != 0) { 49 | if (errno == ENOENT) { 50 | /* Result file not found */ 51 | result = EXIT_NOK; 52 | } else { 53 | perror ("stat"); 54 | fprintf (stderr, "Cannot read status of target file %s\n", argv[argc-1]); 55 | exit (EXIT_INTERNAL_ERROR); 56 | } 57 | } 58 | 59 | 60 | /* Check that each source exists and is before result */ 61 | for (i = 1; i <= argc-2; i++) { 62 | if (strcmp(argv[i], argv[argc-1]) == 0) { 63 | fprintf (stderr, "SEMANTIC ERROR: Source file %s is also the result file.\n", 64 | argv[i]); 65 | fprintf (stderr, " Usage : %s { } \n", 66 | prog_name(argv[0])); 67 | } 68 | if (stat (argv[i], &bs) != 0) { 69 | perror ("stat"); 70 | fprintf (stderr, "Cannot read status of source file %s\n", argv[i]); 71 | result = EXIT_SRC_NOT_FOUND; 72 | } else { 73 | /* time_t (buffer.st_mtime) of last modif is int */ 74 | if ( (result == EXIT_OK) && (br.st_mtime <= bs.st_mtime) ) { 75 | /* Source files exist so far and this one is after result */ 76 | result = EXIT_NOK; 77 | } 78 | } 79 | } 80 | 81 | /* Done */ 82 | exit (result); 83 | } 84 | 85 | -------------------------------------------------------------------------------- /substit/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | EXES := substit 4 | 5 | include $(TEMPLATES)/c.mk 6 | 7 | -------------------------------------------------------------------------------- /svn_tree/callbacks.h: -------------------------------------------------------------------------------- 1 | #ifndef CALLBACKS_H 2 | #define CALLBACKS_H 3 | 4 | /**********************************************/ 5 | /****** Function prototypes for svn_tree *****/ 6 | /********************************************/ 7 | 8 | #include "svn_includes.h" 9 | 10 | #include "utilities.h" 11 | 12 | /* Max size of path */ 13 | #define PATH_LENGTH 256 14 | 15 | /* The specific error to abort iterations */ 16 | #define ABORT_ITERATIONS SVN_ERR_CL_NO_EXTERNAL_MERGE_TOOL 17 | 18 | /* Structure to hold node values of source and destination revisions */ 19 | typedef struct { 20 | url_t src_path; 21 | url_t dst_path; 22 | long int src_rev; 23 | long int dst_rev; 24 | date_t src_date; 25 | date_t dst_date; 26 | } node_type; 27 | 28 | /* Structure to hold info with action type + two path values */ 29 | typedef enum {DELETE=-2, MOVE=-1, OTHER=0, COPY=1} action_kind; 30 | typedef struct { 31 | action_kind action; 32 | url_t src_path; 33 | url_t dst_path; 34 | label_kind src_kind; 35 | label_kind dst_kind; 36 | } source_dest_values; 37 | 38 | typedef struct { 39 | url_t repository_url; 40 | url_t current_url; 41 | } urls_type; 42 | 43 | typedef char tag_path_type[PATH_LENGTH+1]; 44 | 45 | /* Callbacks for promt of authentication */ 46 | extern svn_error_t * my_simple_prompt_callback( 47 | svn_auth_cred_simple_t **cred, 48 | void *baton, 49 | const char *realm, 50 | const char *username, 51 | svn_boolean_t may_save, 52 | apr_pool_t *pool); 53 | extern svn_error_t * my_username_prompt_callback( 54 | svn_auth_cred_username_t **cred, 55 | void *baton, 56 | const char *realm, 57 | svn_boolean_t may_save, 58 | apr_pool_t *pool); 59 | 60 | /* Callback to get current URL */ 61 | extern svn_error_t * client_info_cb( 62 | void *baton, 63 | const char *target, 64 | const svn_info_t *info, 65 | apr_pool_t *pool); 66 | 67 | /* Callback to retrieve creation revision number + date */ 68 | extern svn_error_t * log_entry_cb( 69 | void * baton, 70 | svn_log_entry_t *log_entry, 71 | apr_pool_t *pool); 72 | /* Getting the action (COPY = 1; MOVE = -1 or OTHER = 0) in "log_entry_cb" */ 73 | extern void get_action (apr_hash_t *hash_table, apr_pool_t *pool, 74 | source_dest_values *source_dest); 75 | 76 | /* Store short revision list; -b option */ 77 | extern svn_error_t * log_srevlist_cb( 78 | void * baton, 79 | svn_log_entry_t *log_entry, 80 | apr_pool_t *pool); 81 | 82 | /* Store long revision list */ 83 | extern svn_error_t * log_frevlist_cb( 84 | void * baton, 85 | svn_log_entry_t *log_entry, 86 | apr_pool_t *pool); 87 | 88 | /* Get list of tag names */ 89 | extern svn_error_t * 90 | print_dirent_cb(void *baton, 91 | const char *path, 92 | const svn_dirent_t *dirent, 93 | const svn_lock_t *lock, 94 | const char *abs_path, 95 | apr_pool_t *pool); 96 | 97 | #endif 98 | 99 | -------------------------------------------------------------------------------- /svn_tree/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | # SVN and APACHE includes and libs 4 | SVN := /usr/local 5 | APACHE=/usr/local/apr 6 | 7 | SVN_INC := $(SVN)/include/subversion-1 8 | SVN_LIB := $(SVN)/lib 9 | 10 | APACHE_INC := $(APACHE)/include/apr-1 11 | APACHE_LIB := $(APACHE)/lib 12 | 13 | # Local 14 | DINCL := boolean 15 | DLIBA := dynlist 16 | 17 | LIBS := util 18 | EXES := svn_tree 19 | 20 | OBJS_libutil := callbacks utilities 21 | 22 | CFLAGS = -I$(APACHE_INC) -I$(SVN_INC) 23 | 24 | LARGS_svn_tree := -L$(SVN_LIB) -lsvn_client-1 $(APACHE_LIB)/libapr-1.a 25 | LIBS_svn_tree := libutil 26 | 27 | include $(TEMPLATES)/c.mk 28 | 29 | CCOPT := $(CCOPT:-pedantic=) 30 | 31 | -------------------------------------------------------------------------------- /svn_tree/svn_includes.h: -------------------------------------------------------------------------------- 1 | #ifndef SVN_INCLUDES_H 2 | #define SVN_INCLUDES_H 3 | 4 | /* Includes needed to use svn */ 5 | #include 6 | typedef __off64_t off64_t; 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #define APR_WANT_STDIO 18 | #define APR_WANT_STRFUNC 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #endif 41 | 42 | -------------------------------------------------------------------------------- /svn_tree/utilities.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILITIES_H 2 | #define UTILITIES_H 3 | 4 | #include "boolean.h" 5 | 6 | /**********************************/ 7 | /*** Prototypes for utilities.c ***/ 8 | /**********************************/ 9 | 10 | /* Defines array size to store URL */ 11 | #define PATH_MAX_LEN 1024 12 | #define URL_MAX_LEN (10+256+PATH_MAX_LEN) 13 | typedef char url_t[URL_MAX_LEN+1]; 14 | 15 | /* Defines array size to store date of type '2009-07-20T14:30:17\0' */ 16 | #define DATE_LENGTH 19 17 | typedef char date_t[DATE_LENGTH+1]; 18 | 19 | /* Modes depend from user input arguments */ 20 | typedef enum {URL_MODE, CUR_MODE, ALL_MODE} mode_kind; 21 | 22 | /* Enums for defining path and action type */ 23 | typedef enum {INVALID=0, TRUNK, BRANCH, TAG} label_kind; 24 | 25 | /* Error message in case of fatal error */ 26 | extern void error_data (const char *msg, const char *data); 27 | 28 | /* In any kind of fatal error */ 29 | extern void error (const char *msg); 30 | 31 | /* Put command line help */ 32 | extern void put_help (const char *prog); 33 | 34 | /* Debug */ 35 | extern void debug1 (int severity, const char *msg); 36 | extern void debug2 (int severity, const char *msg, const char *data); 37 | extern void debug3 (int severity, const char *msg, const char *data, 38 | const char *extra); 39 | 40 | /* Modifying SVN output date to readable format */ 41 | extern void svn_date_to_normal (char *date); 42 | 43 | /* Check that the action is not against a file. 44 | Function checks number of '/' in key path. 45 | Return kind of label */ 46 | extern label_kind compare_path (const char *path); 47 | 48 | /* Skip info after label (keep name) */ 49 | extern void get_node_path (char *string); 50 | 51 | /* Check URL: return addr of label (trunk/tags/branches) */ 52 | extern char * url_check (const char *url, boolean allow_trunk); 53 | 54 | /* Check if the argument is URL */ 55 | extern boolean is_url (const char *url); 56 | 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /synchro/gorgy_decode.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "gorgy_decode.h" 5 | 6 | 7 | int gorgy_decode (char frame[], struct timeval *p_new_time, char *p_precision) { 8 | struct tm tms; 9 | time_t new_time_secs; 10 | 11 | /* Decode external clock message */ 12 | if (sscanf(frame, "%*4s %d/%d/%d %d:%d:%d%c\n", 13 | &tms.tm_mday, &tms.tm_mon, 14 | &tms.tm_year, &tms.tm_hour, 15 | &tms.tm_min, &tms.tm_sec, 16 | p_precision) != 7) { 17 | return (-1); 18 | } 19 | tms.tm_year = (tms.tm_year < 70) ? tms.tm_year + 100 : tms.tm_year; 20 | tms.tm_mon -= 1; 21 | tms.tm_isdst = 0; 22 | new_time_secs = mktime(&tms); 23 | if (new_time_secs == (time_t)-1) { 24 | return (-1); 25 | } 26 | p_new_time->tv_sec = new_time_secs; 27 | p_new_time->tv_usec = 0; 28 | 29 | return (0); 30 | } 31 | 32 | -------------------------------------------------------------------------------- /synchro/gorgy_decode.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int gorgy_decode (char frame[], struct timeval *p_new_time, char *p_precision); 4 | -------------------------------------------------------------------------------- /synchro/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | GORGY := gorgy 4 | LIB_TTY := ../$(GORGY)/$(LIB)/libtty.a 5 | 6 | DINCL := boolean $(GORGY) 7 | DLIBA := adjtime timeval socket_evt mutex sig_util wait_evt 8 | 9 | LIBS := gorgy_decode 10 | EXES := synchro_server synchro_client synchro_serial eti 11 | 12 | OBJS_gorgy_decode := gorgy_decode 13 | 14 | LIBS_synchro_serial := gorgy_decode 15 | LARGS_synchro_serial := $(LIB_TTY) 16 | 17 | LIBS_eti := gorgy_decode 18 | LARGS_eti := $(LIB_TTY) 19 | 20 | include $(TEMPLATES)/c.mk 21 | 22 | -------------------------------------------------------------------------------- /synchro/synchro.h: -------------------------------------------------------------------------------- 1 | #include "timeval.h" 2 | 3 | #define magic_request_value 0x21212121 4 | #define magic_reply_value 0x12121212 5 | 6 | typedef struct { 7 | unsigned int magic_number; 8 | timeout_t request_time; 9 | timeout_t server_time; 10 | } synchro_msg_t; 11 | 12 | -------------------------------------------------------------------------------- /synchro/synchro_client.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "socket.h" 4 | #include "timeval.h" 5 | #include "wait_evt.h" 6 | 7 | #include "synchro.h" 8 | 9 | #define DEFAULT_TIMEOUT_MS 1000 10 | #define DEFAULT_ACCURACY_MS 100 11 | 12 | #define USAGE() {fprintf(stderr, "Usage : synchro_client [ [ ]\n");} 13 | 14 | int main (int argc, char *argv[]) { 15 | 16 | timeout_t timeout; 17 | int timeout_ms; 18 | int accuracy_ms; 19 | soc_token soc = init_soc; 20 | soc_port port_no; 21 | char lan_name[80]; 22 | synchro_msg_t synchro_msg; 23 | soc_length length; 24 | int cr, fd; 25 | boolean read; 26 | unsigned int travel_ms; 27 | 28 | timeout_t request_time, reply_time, travel_delta; 29 | timeout_t accuracy_timeout, wait_timeout; 30 | 31 | 32 | if ( (argc != 2) && (argc != 3) && (argc != 4) ) { 33 | fprintf (stderr, "SYNTAX error : Wrong number of arguments\n"); 34 | USAGE(); 35 | exit (1); 36 | } 37 | 38 | if (argc >= 3) { 39 | timeout_ms = atoi(argv[2]); 40 | if (timeout_ms <= 0) { 41 | fprintf (stderr, "SYNTAX error : Wrong timeout value\n"); 42 | USAGE(); 43 | exit (1); 44 | } 45 | } else { 46 | timeout_ms = DEFAULT_TIMEOUT_MS; 47 | } 48 | wait_timeout.tv_sec = timeout_ms / 1000; 49 | wait_timeout.tv_usec = (timeout_ms % 1000) * 1000; 50 | 51 | if (argc == 4) { 52 | accuracy_ms = atoi(argv[3]); 53 | if (accuracy_ms <= 0) { 54 | fprintf (stderr, "SYNTAX error : Wrong accuracy value\n"); 55 | USAGE(); 56 | exit (1); 57 | } 58 | } else { 59 | accuracy_ms = DEFAULT_ACCURACY_MS; 60 | } 61 | accuracy_timeout.tv_sec = accuracy_ms / 1000; 62 | accuracy_timeout.tv_usec = (accuracy_ms % 1000) * 1000; 63 | 64 | 65 | if (soc_get_local_lan_name(lan_name, sizeof(lan_name)) != SOC_OK) { 66 | perror ("getting lan name"); 67 | exit (1); 68 | } 69 | 70 | if (soc_open(&soc, udp_socket) != SOC_OK) { 71 | perror ("opening socket"); 72 | exit (1); 73 | } 74 | 75 | port_no = atoi(argv[1]); 76 | if (port_no <= 0) { 77 | if (soc_set_dest_name_service(soc, lan_name, true, argv[1]) != SOC_OK) { 78 | perror ("setting destination service"); 79 | exit (1); 80 | } 81 | } else { 82 | if (soc_set_dest_name_port(soc, lan_name, true, port_no) != SOC_OK) { 83 | perror ("setting destination port"); 84 | exit (1); 85 | } 86 | } 87 | 88 | if (soc_get_dest_port(soc, &port_no) != SOC_OK) { 89 | perror ("getting destination port no"); 90 | exit (1); 91 | } 92 | 93 | if (soc_link_port(soc, port_no) != SOC_OK) { 94 | perror ("linking socket"); 95 | exit (1); 96 | } 97 | 98 | /* List for wait */ 99 | if (soc_get_id(soc, &fd) != SOC_OK) { 100 | perror ("getting socket id"); 101 | exit (1); 102 | } 103 | if (evt_add_fd(fd, TRUE) != WAIT_OK) { 104 | perror("Adding fd"); 105 | exit (1); 106 | } 107 | 108 | for (;;) { 109 | synchro_msg.magic_number = magic_request_value; 110 | get_time (&(synchro_msg.request_time)); 111 | 112 | cr = soc_send (soc, (soc_message) &synchro_msg, sizeof(synchro_msg)); 113 | if (cr != SOC_OK) { 114 | perror ("sending request"); 115 | exit (1); 116 | } 117 | 118 | request_time = synchro_msg.request_time; 119 | 120 | for (;;) { 121 | 122 | timeout = wait_timeout; 123 | if (evt_wait (&fd, &read, &timeout) != WAIT_OK) { 124 | perror ("waiting for event"); 125 | exit (1); 126 | } 127 | 128 | if (fd == NO_EVENT) { 129 | printf ("Timeout expired. Giving up.\n"); 130 | exit (2); 131 | } else if (fd <= 0) { 132 | /* Other non fd event */ 133 | continue; 134 | } 135 | 136 | length = sizeof (synchro_msg); 137 | cr = soc_receive (soc, (soc_message) &synchro_msg, length, FALSE); 138 | get_time (&reply_time); 139 | 140 | if ( cr == sizeof (synchro_msg) ) { 141 | if (synchro_msg.magic_number == magic_request_value) { 142 | ; 143 | } else if ( (synchro_msg.magic_number == magic_reply_value) 144 | && (synchro_msg.request_time.tv_sec == request_time.tv_sec) 145 | && (synchro_msg.request_time.tv_usec == request_time.tv_usec) ) { 146 | 147 | travel_delta = reply_time; 148 | (void) sub_time (&travel_delta, &request_time); 149 | if (comp_time(&travel_delta, &accuracy_timeout) > 0) { 150 | printf ("Insuficient accuracy. Skipping...\n"); 151 | break; 152 | } 153 | 154 | /* Compute time (reply + travel/2) and settimofday */ 155 | travel_ms = travel_delta.tv_sec * 1000; 156 | travel_ms += travel_delta.tv_usec / 1000; 157 | incr_time (&synchro_msg.server_time, travel_ms / 2); 158 | 159 | (void) sub_time (&reply_time, &synchro_msg.server_time); 160 | printf ("Synchro %ld.%06d s\n", reply_time.tv_sec, 161 | (int)reply_time.tv_usec); 162 | 163 | if (settimeofday (&synchro_msg.server_time, NULL) < 0) { 164 | perror ("settimeofday"); 165 | exit (1); 166 | } 167 | exit (0); 168 | } else { 169 | fprintf (stderr, "Error : wrong reply received"); 170 | } 171 | 172 | } else if (cr != SOC_OK) { 173 | perror ("receiving reply"); 174 | } else { 175 | fprintf (stderr, "Error : wrong reply received"); 176 | } 177 | } 178 | 179 | /* Reset dest */ 180 | if (soc_set_dest_name_port(soc, lan_name, true, port_no) != SOC_OK) { 181 | perror ("linking socket"); 182 | exit (1); 183 | } 184 | } 185 | } 186 | 187 | -------------------------------------------------------------------------------- /synchro/synchro_serial.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "sig_util.h" 8 | #include "tty.h" 9 | #include "timeval.h" 10 | #include "gorgy_decode.h" 11 | 12 | #define BUFFER_SIZE 1000 13 | 14 | 15 | 16 | extern int fd; 17 | static unsigned char buffer[BUFFER_SIZE]; 18 | static unsigned int index; 19 | 20 | static void store (unsigned char oct) { 21 | if (index == BUFFER_SIZE - 1) { 22 | index = 0; 23 | } 24 | buffer[index] = oct; 25 | index ++; 26 | } 27 | 28 | /* static void print (char oct) { 29 | * if (oct < 32) printf ("'%02X' ", (int)oct); 30 | * else printf ("%c ", oct); 31 | * } 32 | */ 33 | 34 | static void decode_and_synchro (void) __attribute__ ((noreturn)); 35 | static void decode_and_synchro (void) { 36 | char precision; 37 | struct timeval new_time, curr_time; 38 | 39 | /* Cancel timer */ 40 | (void) arm_timer (ITIMER_REAL , 0, 0, 0); 41 | 42 | /* Decode external clock message */ 43 | if (gorgy_decode ((char*)buffer, &new_time, &precision) < 0) { 44 | fprintf (stderr, "ERROR. Wrong time format or value.\n"); 45 | exit (2); 46 | } 47 | if (precision == '?') { 48 | fprintf (stderr, "ERROR. Bad precision.\n"); 49 | exit (2); 50 | } else if (precision == '#') { 51 | fprintf (stderr, "WARNING. degraded precision.\n"); 52 | } else { 53 | fprintf (stderr, "INFO. good precision.\n"); 54 | } 55 | 56 | /* For computing delta */ 57 | if (gettimeofday(&curr_time, (struct timezone*) NULL) == -1) { 58 | perror ("ERROR. Gettimeofday"); 59 | exit (2); 60 | } 61 | 62 | /* Set time */ 63 | if (settimeofday(&new_time, (struct timezone*) NULL) == -1) { 64 | perror ("ERROR. Settimeofday"); 65 | exit (2); 66 | } 67 | 68 | 69 | /* Print delta */ 70 | (void) sub_time (&new_time, &curr_time); 71 | printf ("Synchro %ld.%06d s\n", new_time.tv_sec, (int)new_time.tv_usec); 72 | exit(0); 73 | } 74 | 75 | static void sig_handler(int signum) __attribute__ ((noreturn)); 76 | static void sig_handler(int signum __attribute__ ((unused)) ) { 77 | fprintf (stderr, "ERROR. No time received\n"); 78 | exit (2); 79 | } 80 | 81 | 82 | int main(int argc, char *argv[]) { 83 | unsigned char oct; 84 | 85 | int started; 86 | 87 | if ( argc != 2) { 88 | printf ("SYNTAX ERROR. Usage : serial_spy ::::\n"); 89 | exit (1); 90 | } 91 | 92 | init_tty(argv[1], 1); 93 | 94 | /* Hook signal handler and start 1 timer (3s) */ 95 | if (set_handler (SIGALRM, sig_handler, NULL) == ERR) { 96 | fprintf (stderr, "ERROR. Setting signal handler\n"); 97 | exit (2); 98 | } 99 | if (arm_timer (ITIMER_REAL , 3, 0, 0) == -1) { 100 | fprintf (stderr, "ERROR. Starting timer\n"); 101 | exit (2); 102 | } 103 | 104 | 105 | started = 0; 106 | index = 0; 107 | 108 | for(;;) { 109 | read_tty (&oct, 1); 110 | if (oct == 0x02) started = 1; 111 | if (started) { 112 | store (oct); 113 | if (oct == 0x0d) { 114 | decode_and_synchro(); 115 | } 116 | } 117 | } 118 | } 119 | 120 | -------------------------------------------------------------------------------- /synchro/synchro_server.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #ifdef UBSS 5 | #include "bs.h" 6 | #include "scm.h" 7 | #include "npm.h" 8 | #endif 9 | 10 | #include "socket.h" 11 | #include "timeval.h" 12 | 13 | #include "synchro.h" 14 | 15 | #define USAGE() {fprintf(stderr, "Usage : synchro_server \n");} 16 | 17 | int main (int argc, char *argv[]) { 18 | 19 | soc_token soc = init_soc; 20 | soc_port port_no; 21 | synchro_msg_t synchro_msg; 22 | soc_length length; 23 | int cr; 24 | 25 | #ifdef UBSS 26 | if (npm_bs_init()==BS_ERROR) { 27 | scm_bscall_error(); 28 | exit (1); 29 | } 30 | #endif 31 | 32 | if (argc != 2) { 33 | fprintf (stderr, "SYNTAX error : Wrong number of arguments\n"); 34 | USAGE(); 35 | exit (1); 36 | } 37 | 38 | /* Create socket and bind to service */ 39 | if (soc_open(&soc, udp_socket) != SOC_OK) { 40 | perror ("opening socket"); 41 | exit (2); 42 | } 43 | 44 | port_no = atoi(argv[1]); 45 | if (port_no <= 0) { 46 | if (soc_link_service(soc, argv[1]) != SOC_OK) { 47 | perror ("linking socket"); 48 | exit (1); 49 | } 50 | } else { 51 | if (soc_link_port(soc, port_no) != SOC_OK) { 52 | perror ("linking socket"); 53 | exit (1); 54 | } 55 | } 56 | 57 | #ifdef UBSS 58 | if (npm_proc_online()==BS_ERROR) { 59 | scm_bscall_error(); 60 | exit (1); 61 | } 62 | #else 63 | printf ("Server ready.\n"); 64 | #endif 65 | 66 | 67 | /* Wait for request and reply with current time */ 68 | for (;;) { 69 | length = sizeof (synchro_msg); 70 | cr = soc_receive (soc, (soc_message) &synchro_msg, length, FALSE); 71 | if ( (cr == sizeof (synchro_msg)) 72 | && (synchro_msg.magic_number == magic_request_value) ) { 73 | 74 | synchro_msg.magic_number = magic_reply_value; 75 | get_time (&(synchro_msg.server_time)); 76 | length = cr; 77 | cr = soc_send (soc, (soc_message) &synchro_msg, length); 78 | if (cr != SOC_OK) { 79 | perror ("sending reply"); 80 | } 81 | } else if (cr != SOC_OK) { 82 | perror ("receiving request"); 83 | } else { 84 | fprintf (stderr, "Error : wrong request received"); 85 | } 86 | } 87 | } 88 | 89 | -------------------------------------------------------------------------------- /t_malloc/killer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main (int argc, char *argv[]) { 6 | 7 | int pid = atoi(argv[1]); 8 | 9 | if (argc == 2) { 10 | pid = atoi(argv[1]); 11 | 12 | for (;;) { 13 | kill (pid, SIGUSR1); 14 | } 15 | } 16 | exit(0); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /t_malloc/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | EXES := mallocer killer 4 | 5 | include $(TEMPLATES)/c.mk 6 | 7 | -------------------------------------------------------------------------------- /t_malloc/mallocer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | static char *b0; 7 | static char *p; 8 | static int size_handler; 9 | 10 | static void sig_handler (int sig_num __attribute__ ((unused)) ) { 11 | 12 | if (p == NULL) { 13 | size_handler=rand()%1000+1; 14 | p = malloc (size_handler); 15 | } 16 | } 17 | 18 | int main(void) { 19 | int size; 20 | 21 | (void) signal (SIGUSR1, sig_handler); 22 | 23 | p = NULL; 24 | 25 | for (;;) { 26 | size = rand() %1000+1; 27 | b0 = malloc (size); 28 | if (p != NULL) { 29 | if ( (p >= b0) && (p <= b0 + size) ) { 30 | printf ("Fatal! %p %p %p\n" ,b0, p, b0 + size); 31 | printf ("Sizes %d %d\n", size, size_handler); 32 | exit (1); 33 | } 34 | if ( (b0 >= p) && (b0 <= p + size_handler) ) { 35 | printf ("Fatal!! %p %p %p\n" ,b0, p, b0 + size); 36 | printf ("Sizes %d %d\n", size, size_handler); 37 | exit (1); 38 | } 39 | free (p); 40 | p = NULL; 41 | } 42 | free (b0); 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /t_time/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DINCL := boolean 4 | DLIBA := timeval 5 | 6 | EXES := t_time 7 | 8 | include $(TEMPLATES)/c.mk 9 | 10 | -------------------------------------------------------------------------------- /t_time/t_time.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "timeval.h" 4 | 5 | 6 | int main(void) { 7 | timeout_t orig, new; 8 | 9 | get_time (&new); 10 | 11 | do { 12 | get_time (&orig); 13 | } while (comp_time (&orig, &new) == 0); 14 | 15 | do { 16 | get_time (&new); 17 | } while (comp_time (&orig, &new) == 0); 18 | 19 | (void) sub_time (&new, &orig); 20 | 21 | printf ("Tick : %ld sec . %06ld usec \n", new.tv_sec, new.tv_usec); 22 | exit(0); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /tcpdump/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | # -Wunreach fails on last loop 4 | CCOPT_Linux ?= -pedantic -Wall -W -Wpointer-arith \ 5 | -Wbad-function-cast -Wcast-qual -Wcast-align -Wwrite-strings \ 6 | -Wsign-compare -Wstrict-prototypes -Wmissing-prototypes \ 7 | -Wmissing-declarations -Wmissing-noreturn -Winline \ 8 | -Wfloat-equal -Wundef 9 | 10 | EXES := tcpdump 11 | 12 | include $(TEMPLATES)/c.mk 13 | 14 | -------------------------------------------------------------------------------- /term/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | LIBS := libtty 4 | OBJS_libtty := tty 5 | EXES := term 6 | 7 | LIBS_term := libtty 8 | 9 | include $(TEMPLATES)/c.mk 10 | 11 | -------------------------------------------------------------------------------- /term/mterm: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | function usage { 3 | echo "Usage: `basename $0` [ -s ] [ ]" >&2 4 | } 5 | 6 | if [ "$1" = "" ] ; then 7 | usage 8 | exit 1 9 | fi 10 | arg_device=$1 11 | device=$1 12 | shift 13 | 14 | speed=115200 15 | if [ "$1" = "-s" ] ; then 16 | if [ "$2" = "" ] ; then 17 | usage 18 | exit 1 19 | fi 20 | speed=$2 21 | shift 22 | shift 23 | fi 24 | 25 | 26 | # Device (console is cua0) 27 | if [ "$arg_device" = "console" ] 28 | then 29 | device=cua0 30 | args=noctsrts 31 | speed=9600 32 | else 33 | args=$* 34 | fi 35 | 36 | echo term $device:8:N:1:$speed $args 37 | term $device:8:N:1:$speed $args 38 | 39 | -------------------------------------------------------------------------------- /term/term.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | /* Terminal on a serial line */ 10 | 11 | #include "tty.h" 12 | 13 | int main (int argc, char *argv[]) { 14 | 15 | int kfd, tfd; 16 | int nfd; 17 | fd_set fixed_mask, select_mask; 18 | int cr; 19 | char c; 20 | int i; 21 | int echo; 22 | int mapda; 23 | int ctsrts; 24 | 25 | if (argc < 2) { 26 | fprintf (stderr, "Usage %s [ echo ] [ crlf ] [ noctsrts ]\n", 27 | argv[0]); 28 | init_tty("", 0, 0, 0); 29 | exit (1); 30 | } 31 | 32 | echo = 0; 33 | mapda = 0; 34 | ctsrts = 1; 35 | for (i = 2; i < argc; i++) { 36 | if (strcmp(argv[i], "echo") == 0) { 37 | echo = 1; 38 | } else if (strcmp(argv[i], "crlf") == 0) { 39 | mapda = 1; 40 | } else if (strcmp(argv[i], "noctsrts") == 0) { 41 | ctsrts = 0; 42 | } else { 43 | fprintf (stderr, "Usage %s [ echo ] [ crlf ] [ noctsrts ]\n", 44 | argv[0]); 45 | init_tty("", 0, 0, 0); 46 | exit (1); 47 | } 48 | } 49 | 50 | init_tty(argv[1], ctsrts, echo, mapda); 51 | tfd = get_tty_fd(); 52 | printf ("Ready. Exit with Ctrl X.\n"); 53 | 54 | kfd = fileno(stdin); 55 | init_kbd(kfd); 56 | 57 | nfd = tfd; 58 | if (nfd < kfd) nfd = kfd; 59 | FD_ZERO (&fixed_mask); 60 | FD_SET (tfd, &fixed_mask); 61 | FD_SET (kfd, &fixed_mask); 62 | 63 | for (;;) { 64 | memcpy (&select_mask, &fixed_mask, sizeof(fd_set)); 65 | cr = select (nfd+1, &select_mask, (fd_set*)NULL, (fd_set*)NULL, 66 | (struct timeval*)NULL); 67 | if (cr == -1) { 68 | if (errno != EINTR) { 69 | perror ("select"); 70 | } 71 | } else if (cr == 0) { 72 | fprintf (stderr, "select returned 0\n"); 73 | } else { 74 | if (FD_ISSET(kfd, &select_mask) ) { 75 | #ifdef DEBUG 76 | fprintf (stderr, "kbd event selected\n"); 77 | #endif 78 | errno = 0; 79 | cr = read (kfd, &c, 1); 80 | if (cr != 1) { 81 | perror ("read kbd"); 82 | } 83 | #ifdef DEBUG 84 | fprintf (stderr, "kbd char read: %c 0x%x\n", c, (int)c); 85 | #endif 86 | 87 | if (c == 0x18) { 88 | /* Exit */ 89 | restore_kbd (kfd); 90 | restore_tty (); 91 | (void) putchar ((int)'\n'); 92 | exit (0); 93 | } 94 | 95 | send_tty (c); 96 | #ifdef DEBUG 97 | fprintf (stderr, "sent to tty.\n"); 98 | #endif 99 | } else if (FD_ISSET(tfd, &select_mask) ) { 100 | #ifdef DEBUG 101 | fprintf (stderr, "tty event selected\n"); 102 | #endif 103 | read_tty (&c); 104 | #ifdef DEBUG 105 | fprintf (stderr, "tty char read: %c %x\n", c, (int)c); 106 | #endif 107 | (void) putchar ((int)c); 108 | #ifdef DEBUG 109 | fprintf (stderr, "sent to display.\n"); 110 | #endif 111 | (void) fflush (stdout); 112 | } else { 113 | fprintf (stderr, "select returned but fd not set\n"); 114 | } 115 | } 116 | 117 | } 118 | 119 | } 120 | 121 | -------------------------------------------------------------------------------- /term/tty.h: -------------------------------------------------------------------------------- 1 | void init_tty (const char *arg, int ctsrts, int echo, int crlf); 2 | 3 | void restore_tty (void); 4 | 5 | void send_tty (char c); 6 | 7 | void read_tty (char *c); 8 | 9 | int get_tty_fd(void); 10 | 11 | void init_kbd (int kfd); 12 | 13 | void restore_kbd (int kfd); 14 | 15 | -------------------------------------------------------------------------------- /time_spy/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DINCL := boolean 4 | DLIBA := timeval socket mutex 5 | 6 | EXES := time_spy 7 | 8 | include $(TEMPLATES)/c.mk 9 | 10 | -------------------------------------------------------------------------------- /time_spy/time_spy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "socket.h" 7 | #include "timeval.h" 8 | 9 | #define MSG_LEN 30 10 | static char msg[MSG_LEN]; 11 | 12 | 13 | static char week_day[7][4] = {"DIM", "LUN", "MAR", "MER", "JEU", "VEN", "SAM"}; 14 | 15 | static void print_time (timeout_t *p_time) { 16 | char *date_str; 17 | char buf[50]; 18 | struct tm *date_struct; 19 | 20 | date_str = ctime ( (time_t*) &(p_time->tv_sec)); 21 | date_struct = gmtime ( (time_t*) &(p_time->tv_sec)); 22 | 23 | 24 | /* msg[0..2] <- day_name */ 25 | msg[ 0] = week_day[date_struct->tm_wday][0]; 26 | msg[ 1] = week_day[date_struct->tm_wday][1]; 27 | msg[ 2] = week_day[date_struct->tm_wday][2]; 28 | 29 | msg[ 3] = ' '; 30 | 31 | /* msg[4..5] <- jj */ 32 | sprintf (buf, "%02d", date_struct->tm_mday); 33 | msg[ 4] = buf[0]; 34 | msg[ 5] = buf[1]; 35 | msg[ 6] = '/'; 36 | /* msg[7..8] <- mm */ 37 | sprintf (buf, "%02d", date_struct->tm_mon+1); 38 | msg[ 7] = buf[0]; 39 | msg[ 8] = buf[1]; 40 | msg[ 9] = '/'; 41 | /* msg[10..11] <- yy */ 42 | msg[10] = date_str[22]; 43 | msg[11] = date_str[23]; 44 | 45 | msg[12] = ' '; 46 | msg[13] = ' '; 47 | 48 | /* msg[14..21] <- hh:mm:ss */ 49 | strncpy (&(msg[14]), &(date_str[11]), 8); 50 | 51 | /* msg 22..28 <- .millisecs */ 52 | msg[22] = '.'; 53 | sprintf (&msg[23], "%06d", (int)p_time->tv_usec); 54 | 55 | msg[29] = '\0'; 56 | 57 | printf ("%s\n", msg); 58 | fflush (stdout); 59 | 60 | } 61 | 62 | static void usage (void) { 63 | printf ("Usage : time_spy\n"); 64 | printf ("or time_spy -C \n"); 65 | printf ("or time_spy -S \n"); 66 | } 67 | 68 | static void single (void) __attribute__ ((noreturn)); 69 | static void single (void) { 70 | timeout_t cur_time, exp_time, delta_time; 71 | int cr; 72 | 73 | get_time (&cur_time); 74 | 75 | exp_time.tv_sec = cur_time.tv_sec + 1; 76 | exp_time.tv_usec = 0; 77 | 78 | 79 | for (;;) { 80 | 81 | 82 | delta_time.tv_sec = exp_time.tv_sec; 83 | delta_time.tv_usec = exp_time.tv_usec; 84 | get_time (&cur_time); 85 | print_time (&cur_time); 86 | if (sub_time (&delta_time, &cur_time) > 0) { 87 | cr = select (0, NULL, NULL, NULL, &delta_time); 88 | } else { 89 | cr = 0; 90 | } 91 | if (cr < 0) { 92 | perror ("select"); 93 | } 94 | exp_time.tv_sec = exp_time.tv_sec + 1; 95 | } 96 | } 97 | 98 | static void client (char *port_def) __attribute__ ((noreturn)); 99 | static void client (char *port_def) { 100 | soc_token soc; 101 | soc_port port_no; 102 | char message[500]; 103 | soc_length length; 104 | timeout_t cur_time; 105 | 106 | if (soc_open(&soc, udp_socket) != SOC_OK) { 107 | perror ("opening socket\n"); 108 | exit (1); 109 | } 110 | 111 | port_no = atoi(port_def); 112 | if (port_no <= 0) { 113 | if (soc_link_service(soc, port_def) != SOC_OK) { 114 | perror ("linking socket\n"); 115 | exit (1); 116 | } 117 | } else { 118 | if (soc_link_port(soc, port_no) != SOC_OK) { 119 | perror ("linking socket\n"); 120 | exit (1); 121 | } 122 | } 123 | 124 | printf ("Client ready.\n"); 125 | 126 | for (;;) { 127 | length = sizeof(message); 128 | if (soc_receive(soc, message, length, TRUE) <= 0) { 129 | perror ("receiving from socket\n"); 130 | } 131 | get_time (&cur_time); 132 | print_time (&cur_time); 133 | } 134 | 135 | } 136 | 137 | static void server (char *port_def, char *server_node) 138 | __attribute__ ((noreturn)); 139 | static void server (char *port_def, char *server_node) { 140 | soc_token soc; 141 | soc_port port_no; 142 | char message[500]; 143 | soc_length length; 144 | timeout_t cur_time, exp_time, delta_time; 145 | int cr; 146 | 147 | if (soc_open(&soc, udp_socket) != SOC_OK) { 148 | perror ("opening socket\n"); 149 | exit (1); 150 | } 151 | 152 | port_no = atoi(port_def); 153 | if (port_no <= 0) { 154 | if (soc_set_dest_name_service(soc, server_node, false, port_def) != SOC_OK) { 155 | perror ("setting destination socket\n"); 156 | exit (1); 157 | } 158 | } else { 159 | if (soc_set_dest_name_port(soc, server_node, false, port_no) != SOC_OK) { 160 | perror ("setting destination socket\n"); 161 | exit (1); 162 | } 163 | } 164 | 165 | printf ("Server ready.\n"); 166 | strcpy (message, "Hello."); 167 | length = strlen(message) +1; 168 | 169 | 170 | get_time (&cur_time); 171 | 172 | exp_time.tv_sec = cur_time.tv_sec + 1; 173 | exp_time.tv_usec = 0; 174 | 175 | 176 | for (;;) { 177 | 178 | 179 | delta_time.tv_sec = exp_time.tv_sec; 180 | delta_time.tv_usec = exp_time.tv_usec; 181 | get_time (&cur_time); 182 | if (sub_time (&delta_time, &cur_time) > 0) { 183 | cr = select (0, NULL, NULL, NULL, &delta_time); 184 | } else { 185 | cr = 0; 186 | } 187 | if (cr < 0) { 188 | perror ("select"); 189 | } 190 | exp_time.tv_sec = exp_time.tv_sec + 1; 191 | 192 | if (soc_send(soc, message, length) != SOC_OK) { 193 | perror ("sending to socket\n"); 194 | } 195 | } 196 | 197 | 198 | } 199 | 200 | 201 | int main (int argc, char *argv[]) { 202 | 203 | if (argc == 1) { 204 | single(); 205 | } else if ((argc == 3) && (strcmp(argv[1], "-C") == 0) ) { 206 | client(argv[2]); 207 | } else if ((argc == 4) && (strcmp(argv[1], "-S") == 0) ) { 208 | server (argv[2], argv[3]); 209 | } else { 210 | usage(); 211 | } 212 | exit(0); 213 | } 214 | 215 | -------------------------------------------------------------------------------- /timeval/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DINCL := boolean 4 | 5 | FILES2LINK := timeval.c timeval.h 6 | LINKFROM := $(HOME)/ada/c 7 | 8 | LIBS := libtimeval 9 | 10 | OBJS_libtimeval := timeval 11 | 12 | include $(TEMPLATES)/c.mk 13 | 14 | -------------------------------------------------------------------------------- /udp_send/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DINCL := boolean 4 | DLIBA := socket mutex get_line 5 | 6 | EXES := udp_send 7 | 8 | include $(TEMPLATES)/c.mk 9 | 10 | -------------------------------------------------------------------------------- /udp_send/udp_send.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | /* Send a text message on UDP */ 7 | 8 | #include "get_line.h" 9 | #include "socket.h" 10 | 11 | static void error(const char *msg, const char *arg) 12 | __attribute__ ((noreturn)); 13 | static void error(const char *msg, const char *arg) { 14 | fprintf(stderr, "ERROR : %s %s\n", msg, arg); 15 | fprintf(stderr, "Usage : udp_send : [ ]\n"); 16 | fprintf(stderr, " ::= lan | host\n"); 17 | fprintf(stderr, " ::= | \n"); 18 | fprintf(stderr, " ::= | \n"); 19 | fprintf(stderr, "Reads stdin if no .\n"); 20 | exit (1); 21 | } 22 | 23 | static char message[1024 *1024]; 24 | 25 | int main (int argc, char *argv[]) { 26 | boolean dest_lan; 27 | char host_name[1024]; 28 | soc_host host_no; 29 | char port_name[256]; 30 | soc_port port_no; 31 | soc_token soc = init_soc; 32 | char buffer[1024]; 33 | int i, res, len; 34 | boolean interactive; 35 | 36 | /* Parse command line arguments */ 37 | /* Syntax is udp_send lan/host : [ ] */ 38 | if (argc < 3) error("Invalid number of arguments", ""); 39 | 40 | if (strcmp(argv[1], "host") == 0) { 41 | dest_lan = false; 42 | } else if (strcmp(argv[1], "lan") == 0) { 43 | dest_lan = true; 44 | } else { 45 | error("Invalid argument", argv[1]); 46 | } 47 | interactive = (isatty(0) == 1); 48 | 49 | /* Locate ':' in dest:port */ 50 | strcpy (host_name, argv[2]); 51 | res = -1; 52 | for (i = 0; i < (int) strlen(host_name); i++) { 53 | if (host_name[i] == ':') { 54 | if (res != -1) { 55 | error ("Invalid destination", host_name); 56 | } 57 | res = i; 58 | } 59 | } 60 | /* ':' must exist and not at beginning or end */ 61 | if ( (res == -1) || (res == 0) || (res == (int)strlen (host_name) - 1) ) { 62 | error ("Invalid destination", host_name); 63 | } 64 | host_name[res] = '\0'; 65 | strcpy (port_name, &host_name[res+1]); 66 | 67 | /* Create socket */ 68 | res = soc_open(&soc, udp_socket); 69 | if (res != SOC_OK) { 70 | error("Socket creation", soc_error(res)); 71 | } 72 | 73 | /* Set destination */ 74 | if (soc_str2host (host_name, &host_no) == SOC_OK) { 75 | if (soc_str2port (port_name, &port_no) == SOC_OK) { 76 | res = soc_set_dest_host_port(soc, &host_no, port_no); 77 | } else { 78 | res = soc_set_dest_host_service (soc, &host_no, port_name); 79 | } 80 | } else { 81 | if (soc_str2port (port_name, &port_no) == SOC_OK) { 82 | res = soc_set_dest_name_port(soc, host_name, dest_lan, port_no); 83 | } else { 84 | res = soc_set_dest_name_service(soc, host_name, dest_lan, port_name); 85 | } 86 | } 87 | if (res != SOC_OK) { 88 | error("Setting destination", soc_error(res)); 89 | } 90 | 91 | /* Link */ 92 | if (soc_str2port (port_name, &port_no) == SOC_OK) { 93 | res = soc_link_port(soc, port_no); 94 | } else { 95 | res = soc_link_service (soc, port_name); 96 | } 97 | if (res != SOC_OK) { 98 | error("Linking to port", soc_error(res)); 99 | } 100 | 101 | /* Build or read message */ 102 | message[0] = '\0'; 103 | if (argc > 3) { 104 | /* Concatenate arguments separated by spaces */ 105 | for (i = 3; i < argc; i++) { 106 | if (i != 3) { 107 | strcat (message, " "); 108 | } 109 | strcat (message, argv[i]); 110 | } 111 | len = strlen(message); 112 | } else { 113 | /* Read from stdin */ 114 | if (interactive) { 115 | printf ("Enter message to send (end with Ctrl-D): "); 116 | fflush (stdout); 117 | } 118 | len = 0; 119 | for (;;) { 120 | /* Read a buffer of data from stdin */ 121 | res = (int) get_text (NULL, buffer, sizeof(buffer)); 122 | if (res == 0) { 123 | /* End of input flow */ 124 | break; 125 | } 126 | /* Concatenate to message */ 127 | memmove (&message[len], buffer, res); 128 | len += res; 129 | } 130 | if (interactive) { 131 | printf ("\n"); 132 | } 133 | } 134 | 135 | /* Send */ 136 | res = soc_send (soc, message, (soc_length)len); 137 | if (res != SOC_OK) { 138 | error("Sending message", soc_error(res)); 139 | } 140 | 141 | /* Receive */ 142 | res = soc_set_blocking (soc, FALSE); 143 | sleep (1); 144 | for (;;) { 145 | res = soc_receive (soc, message, (soc_length)sizeof(message), TRUE); 146 | if (res > 0) { 147 | message[res] = '\0'; 148 | printf ("-->%s<\n", message); 149 | } else { 150 | break; 151 | } 152 | } 153 | 154 | exit (0); 155 | } 156 | 157 | -------------------------------------------------------------------------------- /udpspy/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DINCL=boolean 4 | DLIBA=socket_evt timeval wait_evt 5 | 6 | 7 | EXES := udpspy 8 | LIBS := libutil 9 | 10 | OBJS_libutil := util 11 | 12 | LIBS_udpspy := libutil 13 | LARGS_udpspy := -lpthread -lm 14 | 15 | include $(TEMPLATES)/c.mk 16 | 17 | -------------------------------------------------------------------------------- /udpspy/udpspy.c: -------------------------------------------------------------------------------- 1 | #include "timeval.h" 2 | #include "socket.h" 3 | #include "wait_evt.h" 4 | #include "util.h" 5 | 6 | /* Dump messages received on a UDP/IPM port */ 7 | 8 | /* Message read */ 9 | static char message[128*1024]; 10 | 11 | int main (const int argc, const char *argv[]) { 12 | /* Result of operation */ 13 | int res; 14 | char buffer[255]; 15 | 16 | /* The socket and its fd */ 17 | soc_token socket = init_soc; 18 | int fd; 19 | 20 | /* Event result */ 21 | boolean read; 22 | timeout_t timeout; 23 | int evtfd; 24 | 25 | /* parse arguments */ 26 | parse_args (argc, argv); 27 | 28 | /* Create socket and get fd */ 29 | if ( (res = soc_open (&socket, udp_socket)) != SOC_OK) { 30 | trace ("soc_open error", soc_error (res)); 31 | error ("cannot open socket", ""); 32 | } 33 | if ( (res = soc_get_id (socket, &fd)) != SOC_OK) { 34 | trace ("soc_get_id error", soc_error (res)); 35 | error ("cannot get socket fd", ""); 36 | } 37 | /* Bind socket to lan:port */ 38 | bind_socket (socket); 39 | 40 | /* Attach fd for reading */ 41 | if ( (res = evt_add_fd (fd, TRUE)) != WAIT_OK) { 42 | trace ("evt_add_fd error", ""); 43 | error ("cannot add fd", ""); 44 | } 45 | 46 | /* Main loop */ 47 | timeout.tv_sec = -1; 48 | timeout.tv_usec = -1; 49 | for (;;) { 50 | /* Infinite wait for events */ 51 | if ( (res = evt_wait (&evtfd, & read, &timeout)) != WAIT_OK) { 52 | trace ("evt_wait error", ""); 53 | error ("cannot wait for event", ""); 54 | } 55 | /* Analyse event */ 56 | if (evtfd == SIG_EVENT) { 57 | if (get_signal() == SIG_TERMINATE) { 58 | /* Sigterm/sigint */ 59 | break; 60 | } /* else unexpected signal => drop */ 61 | } else if (evtfd == fd) { 62 | /* Got a packet: read it */ 63 | res = soc_receive (socket, message, sizeof(message), TRUE); 64 | if (res < 0) { 65 | sprintf (buffer, "%d", res); 66 | trace ("soc_receive error", soc_error (res)); 67 | error ("cannot read message", soc_error(res)); 68 | } else { 69 | if (res > (int)sizeof(message)) { 70 | sprintf (buffer, "%d", res); 71 | trace ("soc_receive truncated message length", "buffer"); 72 | res = (int)sizeof(message); 73 | } 74 | /* Put message info */ 75 | display (socket, message, res); 76 | } 77 | } else if (evtfd >= 0) { 78 | /* Unexpected event on an unexpected fd */ 79 | sprintf (buffer, "%d", evtfd); 80 | trace ("evt_wait got unexpected even on fd", "buffer"); 81 | error ("even on unexpected fd", ""); 82 | } 83 | 84 | } /* Main loop */ 85 | 86 | /* Done */ 87 | (void) evt_del_fd (fd, TRUE); 88 | (void) soc_close (&socket); 89 | the_end (); 90 | } 91 | 92 | -------------------------------------------------------------------------------- /udpspy/util.h: -------------------------------------------------------------------------------- 1 | #include "socket.h" 2 | 3 | /* Parse arguments, exit on error */ 4 | extern void parse_args (const int argc, const char *argv[]); 5 | 6 | /* Trace a message if debug is on */ 7 | extern void trace (const char *msg, const char *arg); 8 | 9 | /* Display usage message on stderr */ 10 | extern void usage (void); 11 | 12 | /* Display an error message on stderr and exit */ 13 | extern void error (const char *msg, const char *arg) 14 | __attribute__ ((noreturn)); 15 | 16 | /* Bind the socket to the IPM lan and port */ 17 | extern void bind_socket (soc_token socket); 18 | 19 | /* Put message info */ 20 | extern void display (const soc_token socket, 21 | const char *message, const int length); 22 | 23 | /* Execute end of program actions */ 24 | extern void the_end (void) 25 | __attribute__ ((noreturn)); 26 | 27 | -------------------------------------------------------------------------------- /unlink/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DLIBA := get_line 4 | 5 | EXES := unlink 6 | 7 | include $(TEMPLATES)/c.mk 8 | 9 | -------------------------------------------------------------------------------- /unlink/unlink.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | /* Unlink (rm) a file */ 8 | 9 | #include "get_line.h" 10 | 11 | static void remove_file(char *name) { 12 | if (unlink(name) == 0) { 13 | printf (">%s< deleted.\n", name); 14 | } else { 15 | printf ("Error deleting >%s<. Errno --> %d : %s\n", name, errno, strerror(errno)); 16 | } 17 | } 18 | 19 | int main (int argc, char *argv[]) { 20 | 21 | int i; 22 | char input[500]; 23 | 24 | if (argc == 1) { 25 | 26 | system ("ls"); 27 | for (;;) { 28 | printf ("File name : "); 29 | i = get_line ( (FILE*)NULL, input, sizeof(input)); 30 | if (i < 1) { 31 | break; 32 | } 33 | remove_file(input); 34 | } 35 | 36 | } else { 37 | 38 | for (i = 1; i < argc; i++) { 39 | for (;;) { 40 | printf ("OK to remove file >%s< ? (Y/N/Q) ", argv[i]); 41 | (void) get_line ((FILE*)NULL, input, sizeof(input)); 42 | if ( (strcmp(input, "y") == 0) || (strcmp(input, "Y") == 0) ) { 43 | remove_file(argv[i]); 44 | break; 45 | } else if ( (strcmp(input, "n") == 0) || (strcmp(input, "N") == 0) ) { 46 | break; 47 | } else if ( (strcmp(input, "q") == 0) || (strcmp(input, "Q") == 0) ) { 48 | printf ("Aborted.\n"); 49 | exit(0); 50 | } 51 | } /* for (;;) */ 52 | printf ("\n"); 53 | } /* for each arg */ 54 | 55 | } 56 | printf ("Done.\n"); 57 | exit(0); 58 | } 59 | -------------------------------------------------------------------------------- /vt100/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | LIBS := libvt100 4 | OBJS_libvt100 := vt100 5 | 6 | include $(TEMPLATES)/c.mk 7 | 8 | -------------------------------------------------------------------------------- /vt100/vt100.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "vt100.h" 8 | 9 | #ifdef DEBUG 10 | #define LOG(Arg1, Arg2) (fprintf (stderr, Arg1, Arg2)) 11 | #else 12 | #define LOG(Arg1, Arg2) 13 | #endif 14 | 15 | void clrscr (void) { 16 | char chaine[5]; 17 | 18 | strcpy(chaine," [2J"); 19 | chaine[0]=27; 20 | printf("%s",chaine); 21 | gotoxy (0, 0); 22 | } 23 | 24 | void gotoxy (int x, int y) { 25 | char chaine2[15]; 26 | 27 | strcpy(chaine2," [ ; H"); 28 | chaine2[0]=27; 29 | chaine2[2]='0'+x/10; 30 | chaine2[3]='0'+x%10; 31 | chaine2[5]='0'+y/10; 32 | chaine2[6]='0'+y%10; 33 | printf("%s",chaine2); 34 | } 35 | 36 | void open_keybd (void) { 37 | system("stty -echo raw"); 38 | } 39 | 40 | void close_keybd (void) { 41 | system("stty echo -raw"); 42 | } 43 | 44 | #define cprintf printf 45 | 46 | void highvideo (void) { 47 | char chaine[9]; 48 | 49 | strcpy(chaine ," [1m"); 50 | chaine[0]=27; 51 | printf("%s",chaine); 52 | } 53 | 54 | void lowvideo (void) { 55 | char chaine[9]; 56 | 57 | strcpy(chaine ," [0m"); 58 | chaine[0]=27; 59 | printf("%s",chaine); 60 | } 61 | 62 | long long filelength (int fd) { 63 | struct stat buf; 64 | 65 | fstat(fd, &buf); 66 | return ((long long) buf.st_size); 67 | } 68 | 69 | 70 | 71 | static char escape_sequence (void) { 72 | int car; 73 | 74 | car = getchar(); 75 | LOG(" E1-> >%02X<\n", car); 76 | 77 | switch (car) { 78 | case 0x5b: 79 | /* Esc [ */ 80 | car = getchar(); 81 | LOG(" E2-> >%02X<\n", car); 82 | switch (car) { 83 | case 'A': /* Arrow up */ 84 | return 1; /* Arrow up */ 85 | case 'C': /* Arrow right */ 86 | return 2; /* Arrow right */ 87 | case 'B': /* Arrow down */ 88 | return 3; /* Arrow down */ 89 | case 'D': /* Arrow left */ 90 | return 4; /* Arrow left */ 91 | case '5': /* Page up */ 92 | return 5; /* Page up */ 93 | case '6': /* Page down */ 94 | return 6; /* Page down */ 95 | case 'H': /* Home */ 96 | return 10; /* Home */ 97 | case 'F': /* End */ 98 | return 11; /* End */ 99 | default : 100 | return 0; 101 | } 102 | case 'O': 103 | /* Exc O */ 104 | car = getchar(); 105 | LOG(" E2'-> >%02X<\n", car); 106 | switch (car) { 107 | case 'H': /* Home */ 108 | return 10; /* Home */ 109 | case 'F': /* End */ 110 | return 11; /* End */ 111 | default : 112 | return 0; 113 | } 114 | case 'A': /* Esc A */ 115 | case 'a': /* Esc a */ 116 | return 20; /* Begin page */ 117 | case 'Z': /* Esc Z */ 118 | case 'z': /* Esc z */ 119 | return 19; /* End page */ 120 | case 'H': /* Esc H */ 121 | case 'h': /* Esc h */ 122 | return 10; /* Home */ 123 | case 'E': /* Esc E */ 124 | case 'e': /* Esc e */ 125 | return 11; /* End */ 126 | case 'F': /* Esc F */ 127 | case 'f': /* Esc f */ 128 | return 15; /* Find */ 129 | case 'P': /* Esc P */ 130 | case 'p': /* Esc p */ 131 | return 16; /* Goto page */ 132 | case 'S': /* Esc S */ 133 | case 's': /* Esc s */ 134 | return 17; /* Write */ 135 | case 'U': /* Esc U */ 136 | case 'u': /* Esc u */ 137 | return 23; /* Write */ 138 | case 'X': /* Esc X */ 139 | case 'x': /* Esc x */ 140 | return 18; /* Exit */ 141 | case 'C': /* Esc C */ 142 | case 'c': /* Esc c */ 143 | return 21; /* Exit */ 144 | case 'Q': /* Esc C */ 145 | case 'q': /* Esc c */ 146 | return 22; /* Exit */ 147 | case 0x1B: /* Escape */ 148 | return 0x1B; /* New escape */ 149 | default : 150 | return 0; 151 | } 152 | } 153 | 154 | char read_char (void) { 155 | int car; 156 | 157 | for (;;) { 158 | car = getchar(); 159 | LOG("R-> >%02X<\n", car); 160 | if ( (car > 0x1F) && (car < 0x7F) ) return car; 161 | switch (car) { 162 | case 0x10: /* Ctrl P */ 163 | return 5; /* Pg up */ 164 | case 0x0E: /* Ctrl N */ 165 | return 6; /* Pg down */ 166 | case 0x7F: /* Backspace */ 167 | case 0x08: /* Backspace */ 168 | return 8; /* Backspace */ 169 | case 0x09: /* Tab */ 170 | return 9; /* Tab */ 171 | case 0x0D: /* Return */ 172 | return 13; /* Return */ 173 | case 0x1B: /* Esc */ 174 | while (1) { 175 | car = escape_sequence(); 176 | if (car == 0x00) break; 177 | else if (car != 0x1B) return car; 178 | } 179 | } 180 | } 181 | } 182 | 183 | void beep (unsigned char nb_beeps, 184 | unsigned int frequency __attribute__ ((unused))) { 185 | int i; 186 | 187 | for (i = 1; i <= nb_beeps; i++) { 188 | putchar ((int) 0x07); 189 | 190 | } 191 | } 192 | 193 | -------------------------------------------------------------------------------- /vt100/vt100.h: -------------------------------------------------------------------------------- 1 | /* Clear screen */ 2 | void clrscr (void); 3 | 4 | /* Move to row, col */ 5 | void gotoxy (int x, int y); 6 | 7 | /* Open / close keyboard in raw mode */ 8 | void open_keybd (void); 9 | 10 | void close_keybd (void); 11 | 12 | #define cprintf printf 13 | 14 | /* Swith to bold */ 15 | void highvideo (void); 16 | void lowvideo (void); 17 | 18 | /* Length of a opened file */ 19 | long long filelength (int fd); 20 | 21 | /* Read char */ 22 | /* Special values: */ 23 | /* 01, 02, 03, 04 => Arrow Up/Right/Down/Left */ 24 | /* 05, 06 => Page Up/Down */ 25 | /* 08 => Backspace */ 26 | /* 09 => Tab */ 27 | /* 10, 11 => Home/End */ 28 | /* 13 => Return */ 29 | /* 19, 20 => End/Begin page */ 30 | /* 15, 16, 17, 18, 21, 22, 23 => Esc F/P/X/C/Q/U */ 31 | /* 0x1B => Esc Esc */ 32 | char read_char (void); 33 | 34 | /* Put a BELL char */ 35 | void beep (unsigned char nb_beeps, unsigned int frequency); 36 | 37 | -------------------------------------------------------------------------------- /wait_evt/makefile: -------------------------------------------------------------------------------- 1 | include $(HOME)/Makefiles/common.mk 2 | 3 | DINCL := boolean 4 | DLIBA := timeval 5 | 6 | FILES2LINK := wait_evt.h wait_evt.c 7 | LINKFROM := $(HOME)/ada/c 8 | 9 | LIBS := libwait_evt 10 | 11 | OBJS_libwait_evt := wait_evt 12 | 13 | include $(TEMPLATES)/c.mk 14 | 15 | --------------------------------------------------------------------------------