diff -ru sswriter-vanilla/README sswriter-0.2.4/README --- sswriter-vanilla/README 2008-01-29 06:31:04.000000000 -0500 +++ sswriter-0.2.4/README 2008-05-14 21:38:26.000000000 -0400 @@ -31,6 +31,9 @@ monitoring (/sys/class/hwmon/hwmonN) and the index of the temperature sensor (/sys/class/hwmon/hwmonN/device/tempN_input). + -f --fortune + set the file with a fortune in it. (see README for wmii integration) + FORMAT ~~~~~~ @@ -66,12 +69,23 @@ s Write the swap usage. + f Write "fortune" which consists of an entire text file, specified by + -f. Default location is /tmp/fortune. + t Write the temperature of the sensor number specified by -t. T Write the tempareture of the sensor number specified by -T. % A simple %. +FORTUNE +~~~~~~~ +Suggested wmii integration, add the following in the beginning of wmiirc: +while true; do fortune -s -w > /tmp/fortune; done & + +and then at the very end of wmiirc: +killall wmiirc + EXAMPLES ~~~~~~~~ Only in sswriter-0.2.4/: fortune diff -ru sswriter-vanilla/src/acpi_parsing.c sswriter-0.2.4/src/acpi_parsing.c --- sswriter-vanilla/src/acpi_parsing.c 2008-01-29 06:31:04.000000000 -0500 +++ sswriter-0.2.4/src/acpi_parsing.c 2008-05-14 21:42:11.000000000 -0400 @@ -507,3 +507,29 @@ return snprintf(sbuff, len, "%d", val / 1000); } + + +// ----------------------------------------------------------------------- +// Append a fortune to the string +// ----------------------------------------------------------------------- +unsigned int insert_fortune(char *sbuff, unsigned int len, const char* filename) { + FILE* fortune = NULL; + char filebuff[SBUFF_SZ]; + size_t bytes_read; + char* tmp_char; + + if(filename) fortune = fopen(filename, "r"); + else fortune = fopen("/tmp/fortune", "r"); + + if(!fortune) { + fprintf(stderr, "Invalid fortune file: %s\n", filename); + return 0; + } + bytes_read = fread(filebuff, 1, len, fortune); + fclose(fortune); + while((tmp_char = memchr(filebuff, '\n', bytes_read))) { + *tmp_char = ' '; + } + memcpy(sbuff, filebuff, bytes_read); + return bytes_read; +} diff -ru sswriter-vanilla/src/acpi_parsing.h sswriter-0.2.4/src/acpi_parsing.h --- sswriter-vanilla/src/acpi_parsing.h 2008-01-29 06:31:04.000000000 -0500 +++ sswriter-0.2.4/src/acpi_parsing.h 2008-05-14 21:38:25.000000000 -0400 @@ -97,4 +97,6 @@ unsigned long t_bytes, unsigned long t_last_bytes); int get_wireless_quality(const char *device); +unsigned int insert_fortune(char *sbuff, unsigned int len, const char* filename); + #endif diff -ru sswriter-vanilla/src/cm_parsing.c sswriter-0.2.4/src/cm_parsing.c --- sswriter-vanilla/src/cm_parsing.c 2008-01-29 06:31:04.000000000 -0500 +++ sswriter-0.2.4/src/cm_parsing.c 2008-05-14 21:38:25.000000000 -0400 @@ -20,6 +20,7 @@ #include "cm_parsing.h" #include "sswriter_std.h" #include "acpi_parsing.h" +#include // ----------------------------------------------------------------------- // Print the help usage of skywmii. @@ -38,6 +39,7 @@ printf("%%o\tout rate of the network device\n"); printf("%%p\tcpu number frequency percent (using cpufreq)\n"); printf("%%s\tswap usage\n"); + printf("%%f\tfortune\n"); printf("%%t\ttemperature of the sensor number specified by -t\n"); printf("%%T\ttemperature of the sensor number specified by -T\n"); printf("%%%%\ta single %%\n"); @@ -52,6 +54,7 @@ printf("\t\t\t\tspecify the name of the temperatures sensors\n"); printf("-T --lm-tsensors\t\n"); printf("\t\t\t\tspecify differents couples of hwmon-num/temp-num (see README)\n"); + printf("-f --fortune\tset the file with a fortune in it. (see README for wmii integration)\n"); } @@ -63,6 +66,7 @@ char **devices = NULL; unsigned int battery_warn_limit = 10; char *date_format = NULL; + char *fortune_file = NULL; char **sensors = NULL; unsigned int nb_sensors = 0; unsigned int nb_lm_sensors = 0; @@ -83,6 +87,10 @@ i++; if (i >= argc) break; date_format = argv[i]; + } else if (!strcmp(argv[i], "-f") || !strcmp(argv[i], "--fortune")) { + i++; + if (i >= argc) break; + fortune_file = argv[i]; } else if (devices == NULL && (!strcmp(argv[i], "-D") || !strcmp(argv[i], "--device"))) { int j = i + 1; @@ -145,8 +153,8 @@ if (i == argc - 1) { res = handle_format(argv[i], devices, nb_devices, - battery_warn_limit, date_format, sensors, nb_sensors, - lm_sensors, nb_lm_sensors); + battery_warn_limit, date_format, fortune_file, sensors, + nb_sensors, lm_sensors, nb_lm_sensors); } else { print_usage(argv[0]); } @@ -176,8 +184,8 @@ // ----------------------------------------------------------------------- int handle_format(const char *format, char **net_devices, unsigned int net_nb_devices, unsigned int battery_warn_limit, - const char *date_format, char **sensors, unsigned int nb_sensors, - unsigned int *lm_sensors, unsigned int nb_lm_sensors) { + const char *date_format, const char *fortune_file, char **sensors, + unsigned int nb_sensors, unsigned int *lm_sensors, unsigned int nb_lm_sensors) { char *it = NULL; char line[SBUFF_SZ]; @@ -197,7 +205,7 @@ int fpercent = 0; int warn = 0; - + memset(line, '\0', SBUFF_SZ); // Looping though format string @@ -351,7 +359,6 @@ len = snprintf(line_it, line_left, "%.1lf", net_out); break; - case 'l': #ifdef __WITH_XKB__ len = insert_kbd_numlock(line_it, line_left); @@ -362,6 +369,10 @@ return EXIT_FAILURE; #endif break; + + case 'f': // Fortune + len = insert_fortune(line_it, line_left, fortune_file); + break; default: fprintf(stderr, "Invalid format sequence: %%%c.\n", next); diff -ru sswriter-vanilla/src/cm_parsing.h sswriter-0.2.4/src/cm_parsing.h --- sswriter-vanilla/src/cm_parsing.h 2008-01-29 06:31:04.000000000 -0500 +++ sswriter-0.2.4/src/cm_parsing.h 2008-05-14 21:38:25.000000000 -0400 @@ -32,7 +32,7 @@ int parse_args(int argc, char **argv); int handle_format(const char *format, char **net_devices, unsigned int net_nb_devices, unsigned int battery_warn_limit, - const char *date_format, char **sensors, unsigned int nb_sensors, - unsigned int *lm_sensors, unsigned int nb_lm_sensors); + const char *date_format, const char *fortune_file, char **sensors, + unsigned int nb_sensors, unsigned int *lm_sensors, unsigned int nb_lm_sensors); #endif Only in sswriter-0.2.4/: sswriter