[wiki] [sites] added sprint, the setRoot bug fixed, added for loop for spawn() || levi0x0

From: <git_AT_suckless.org>
Date: Sat, 28 Feb 2015 09:53:40 +0100

commit 721bc541169be09cfc80501e781a4bf334e056ba
Author: levi0x0 <levi0x0x_AT_gmail.com>
Date: Sat Feb 28 10:51:17 2015 +0000

    added sprint, the setRoot bug fixed, added for loop for spawn()

diff --git a/dwm.suckless.org/dwmstatus/barM.c b/dwm.suckless.org/dwmstatus/barM.c
index 6cf1f2e..f45f18a 100644
--- a/dwm.suckless.org/dwmstatus/barM.c
+++ b/dwm.suckless.org/dwmstatus/barM.c
_AT_@ -11,33 +11,60 @@
  * Read main() to configure your new status Bar.
  *
  * compile: gcc -o barM barM.c -lX11
+ *
+ * mv barM /usr/local/bin/
  */
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
 #include <string.h>
+#include <stdarg.h>
 #include <X11/Xlib.h>
 
-#define VERSION "0.10"
-#define TIME_FORMAT " (%H:%M) (%d-%m-%Y)"
+/*
+ * Put this in your .xinitrc file:
+ *
+ * while true;do
+ * $(barM)
+ * done &
+ *
+ */
+
+#define VERSION "0.11"
+#define TIME_FORMAT "(%H:%M) (%d-%m-%Y)"
 #define MAXSTR 1024
 
-char * TimeADate(void) {
- static char buffer[MAXSTR];
+static char status[MAXSTR];
 
- /* get time*/
- time_t now = time(0);
+/*append here your commands*/
+char *commands[] = {"uname",
+ "free -mh | awk 'NR==2{print $3\"/\"$2}'"
+};
 
+/* will append the buffer to status*/
+void sprint(char *format, ...) {
+ va_list li;
+ static char s[MAXSTR];
+ va_start(li, format);
+ vsprintf(s, format, li);
+ va_end(li);
 
- /* Read the time by the foramt*/
- strftime(buffer, MAXSTR, TIME_FORMAT, localtime(&now));
+ strcat(status, s);
+}
 
- /* Return the buffer content*/
- return buffer;
+/* returen the date*/
+char * date(void) {
+ static char date[MAXSTR];
+
+ time_t now = time(0);
+
+ strftime(date, MAXSTR, TIME_FORMAT, localtime(&now));
+ return date;
 }
 
 
+/* open a pipe for a new coomand and return the output*/
 char * spawn(char *c) {
         FILE *proc;
         static char buffer[MAXSTR];
_AT_@ -57,7 +84,6 @@ char * spawn(char *c) {
 void XSetRoot(char *name) {
         Display *display;
 
- /* try open display*/
         if (( display = XOpenDisplay(0x0)) == NULL ) {
                 fprintf(stderr, "[barM] cannot open display!
");
                 exit(1);
_AT_@ -69,15 +95,16 @@ void XSetRoot(char *name) {
         XCloseDisplay(display);
 }
 
-int main(int argc, char **argv) {
- char status[MAXSTR];
-
- sprintf(status, "(%s) %s", spawn("free -mh | awk 'NR==2{print $3\"/\"$2}'"),
- TimeADate());
+int main(int argc, char **argv) {
+ int i = 0;
+ for(i = 0; commands[i]; i++ ) {
+ sprint("(%s) ", spawn(commands[i]));
+ }
 
+ sprint("%s", date());
         XSetRoot(status);
 
- /*sleep function*/
+ /* sleep by default you dont need to add it to your bash*/
         sleep(1);
 
         return 0;
Received on Sat Feb 28 2015 - 09:53:40 CET

This archive was generated by hypermail 2.3.0 : Thu Jun 18 2015 - 17:40:12 CEST