{"id":26,"date":"2006-03-29T09:42:30","date_gmt":"2006-03-29T08:42:30","guid":{"rendered":"http:\/\/my.stargazer.at\/?p=26"},"modified":"2011-03-18T13:32:23","modified_gmt":"2011-03-18T12:32:23","slug":"hols-der-geier-mit-dem-compile-nur-wann-endlich","status":"publish","type":"post","link":"https:\/\/my.stargazer.at\/de\/2006\/03\/29\/hols-der-geier-mit-dem-compile-nur-wann-endlich\/","title":{"rendered":"Hol&#8217;s der Geier mit dem Compile &#8211; nur wann endlich?"},"content":{"rendered":"<p>Wie oft stellen sich User wie ich die Frage, wie weit der Compile ist bzw wieviel noch fehlt&#8230;<\/p>\n<p>Im Gentoo-Wiki habe ich folgenden C++ L\u00f6sungsansatz gefunden, welchen ich als <em>eprogress.cpp<\/em> ablege und schliesslich mit g++ compile (<em>g++ eprogress.cpp -o eprogress<\/em>):<\/p>\n<p><!--more--><\/p>\n<blockquote><p><code>#include <dirent .h><br \/>\n#include \"fcntl.h\"<br \/>\n#include <string><br \/>\n#include <fstream><br \/>\nusing namespace std;<\/p>\n<p>#define srccount 5<br \/>\n#define objcount 2<\/p>\n<p>int countfiles(char *path, int& todo, int& done);<br \/>\nint dft(char *name);<br \/>\nint findproc(char *name);<\/p>\n<p>int main() {<br \/>\n  char *path, *action;<br \/>\n  char line[256];<br \/>\n  char *est;<br \/>\n  est = \"\";<br \/>\n  int done = 0, todo = 0, percent = 0;<br \/>\n  path = \"\/usr\/tmp\/portage\/\";<br \/>\n  struct dirent *entry;         \/\/This structure will hold file information<br \/>\n  struct stat file_status;      \/\/This structure will be used to query file status<br \/>\n  DIR *dir = opendir(path);     \/\/This pointer references the directory stream<\/p>\n<p>  \/\/  printf(\"Emerge Progress v4.20 C++:\\n\");<br \/>\n  \/\/Make sure we have a directory stream pointer<br \/>\n  if (!dir) { perror(\"opendir failure\"); exit(1); }<br \/>\n  chdir(path);<\/p>\n<p>  while ( (entry = readdir(dir)) != NULL) {<br \/>\n    \/\/Don't bother with the .. and . directories<br \/>\n    if ((strcmp(entry->d_name, \".\") != 0) && (strcmp(entry->d_name, \"..\") != 0)) {<br \/>\n      \/\/Get the status info for the current file<br \/>\n      if (stat(entry->d_name, &file_status) == 0) {<br \/>\n        \/\/Is this a directory, or a file?<br \/>\n        if (S_ISDIR(file_status.st_mode)) {<br \/>\n          strcpy(line,entry->d_name);<br \/>\n          strcat(line,\"\/work\");<br \/>\n          todo = 0; done = 0;<\/p>\n<p>          if (countfiles(line,todo,done) == 1) { if (todo == 0) { percent=0; } else { percent=100 * done \/ todo; }<br \/>\n                if (done > todo) {<br \/>\n                        todo = done++;<br \/>\n                        est = \"~\";<br \/>\n                percent=100 * done \/ todo;}<\/p>\n<p>            \/\/Is it running?<br \/>\n            if (findproc(entry->d_name) == 1) { action=\"C\"; } else { action=\"X\"; }<br \/>\n            printf(\"  * [%s] %s: %d\/%d -  %s%d%\\n\",action,entry->d_name,done,todo,est,percent);<br \/>\n          }<br \/>\n          chdir(path);<br \/>\n        }<br \/>\n      }<br \/>\n    }<br \/>\n  }<\/p>\n<p>  \/\/Make sure we close the directory stream<br \/>\n  if (closedir(dir) == -1) { perror(\"closedir failure\"); exit(1); }<br \/>\n}<\/p>\n<p>int countfiles(char *path, int& T, int& D) {<br \/>\n  int c = 0,res = 0;<br \/>\n  struct dirent *entry;<br \/>\n  struct stat file_status;<br \/>\n  DIR *dir = opendir(path);<\/p>\n<p>  if (!dir) { return 0; }<\/p>\n<p>  \/\/Change directory to the given path<br \/>\n  chdir(path);<\/p>\n<p>  \/\/Loop through all files and directories<br \/>\n  while ( (entry = readdir(dir)) != NULL) {<br \/>\n    \/\/Don't bother with the .. and . directories<br \/>\n    if ((strcmp(entry->d_name, \".\") != 0) && (strcmp(entry->d_name, \"..\") != 0)) {<br \/>\n      \/\/Get the status info for the current file<br \/>\n      if (stat(entry->d_name, &file_status) == 0) {<br \/>\n        \/\/Is this a directory, or a file?<br \/>\n        if (S_ISDIR(file_status.st_mode)) {<br \/>\n          \/\/Call countfiles again (recursion) and add the result to the count total<br \/>\n          countfiles(entry->d_name,T,D);<br \/>\n          chdir(\"..\");<br \/>\n        } else {<br \/>\n          \/\/We've found a file, increment the count<br \/>\n          res=dft(entry->d_name);<br \/>\n          if (res==1) { T=T+1; } else if (res==2) { D=D+1; }<br \/>\n        }<br \/>\n      }<br \/>\n    }<br \/>\n  }<\/p>\n<p>  \/\/Make sure we close the directory stream<br \/>\n  if (closedir(dir) == -1) { perror(\"closedir failure\"); exit(1); }<\/p>\n<p>  \/\/Return the file count<br \/>\n  return 1;<br \/>\n}<\/p>\n<p>int dft(char *name)<br \/>\n{<br \/>\n  \/\/Find out file type..<br \/>\n  \/\/0= none<br \/>\n  \/\/1= todo<br \/>\n  \/\/2= done<br \/>\n  int c;<br \/>\n  char * tmp;<br \/>\n  char *src[] = {\".c\/\",\".cpp\/\",\".C\/\",\".java\/\",\".cc\/\"};<br \/>\n  char *obj[] = {\".o\/\",\".class\/\"};<\/p>\n<p>   strcpy(tmp,name);<br \/>\n   strcat(tmp,\"\/\");<br \/>\n   for(c=0; c<srccount ;++c){ if (strstr(tmp,src[c]) !=NULL) { return 1; } }\n   for(c=0; c<objcount;++c){ if (strstr(tmp,obj[c]) !=NULL) { return 2; } }\n\n   \/\/Neither\n   return 0;\n}\n\nint findproc(char *name)\n{\n  \/\/Find the proc of portage\n  int c = 0;\n  char *res;\n  char *path, *tmp;\n  char buffer[256];\n  path = \"\/proc\/\";\n  struct dirent *entry;\n  struct stat file_status;\n  DIR *dir = opendir(path);\n\n  if (!dir) { return 0; }\n\n  \/\/Change directory to the given path\n  chdir(path);\n\n  \/\/Loop through all files and directories\n  while ( (entry = readdir(dir)) != NULL) {\n    \/\/Don't bother with the .. and . directories\n    if ((strcmp(entry->d_name, \".\") != 0) && (strcmp(entry->d_name, \"..\") != 0)) {<br \/>\n      \/\/Get the status info for the current file<br \/>\n      if (stat(entry->d_name, &file_status) == 0) {<br \/>\n        \/\/Is this a directory, or a file?<br \/>\n        if (S_ISDIR(file_status.st_mode)) {<\/p>\n<p>          chdir(entry->d_name);<\/p>\n<p>          ifstream rfile (\"cmdline\");<br \/>\n          if (rfile.is_open()) {<br \/>\n            rfile.getline (buffer,100);<\/p>\n<p>            if (strstr(buffer,name) != NULL) { return 1; }<br \/>\n          }<br \/>\n          rfile.close();<br \/>\n          chdir(\"..\");<\/p>\n<p>        }<br \/>\n      }<br \/>\n    }<br \/>\n  }<\/p>\n<p>  \/\/Make sure we close the directory stream<br \/>\n  if (closedir(dir) == -1) { perror(\"closedir failure\"); exit(1); }<\/p>\n<p>  \/\/Return the file count<br \/>\n  return 0;<br \/>\n}<br \/>\n<\/srccount><\/fstream><\/string><\/dirent><\/code><\/p><\/blockquote>\n<p>Dieses Programm z\u00e4hlt die vorhandenen Source-Dateien und vergleicht sie mit der Anzahl der schon compilierten .o-Files &#8211; dies erm\u00f6glicht uns eine Sch\u00e4tzung, wie weit das aktuelle Programm compiled ist;<\/p>\n<p>So weit so gut &#8211; das Programm mit <em>watch<\/em> aufgerufen aktualisiert den Output periodisch bis es schliesslich mit <em>STRG + C<\/em> abgebrochen wird.<\/p>\n<p><b>Komfort und Tuning:<\/b><br \/>\nF\u00fcr Leute wie mich, die inzwischen auch schon Xorg erobert haben und sich bis zu einem Desktop vorgewagt haben, bietet sich die Verwendung von xosd an:<\/p>\n<blockquote><p><code>eprogress | osd_cat --font=\"-adobe-helvetica-bold-*-*-*-24-*-*-*-*-*-*-*\" -c \"#33CC33\" -A right -o 60 -i 50 -d 3<\/code><\/p><\/blockquote>\n<p>&#8230; was uns einen kleinen Schriftzug mit dem aktuellen Emerge (falls laufend) in die rechte obere Ecke des Bildschirms zaubert, welcher nach 3 Sekunden wieder verschwindet. Ein kleines Bash-Script mit einer Schleife l\u00e4sst den Schriftzug immer wieder aufflackern, was ich pers\u00f6nlich als st\u00f6rend empfinde. Mein Workaround sieht wie folgt aus:<\/p>\n<blockquote><p><code>#!\/bin\/bash<br \/>\nwhile true; do<br \/>\n  eprogress | osd_cat --font=\"-adobe-helvetica-bold-*-*-*-24-*-*-*-*-*-*-*\" -c \"#33CC33\" -A right -o 60 -i 50 -d 3 &<br \/>\n  sleep 2.7s<br \/>\ndone<\/code><\/p><\/blockquote>\n<p>Xosd_cat wird in den Hintergrund versetzt und alle 2,7 Sekunden aufgerufen. Da eprogress eine gewisse Zeit ben\u00f6tigt bis es seinen Job erledigt hat und die Ausgabe weitergegeben wird liegen die beiden Schriftz\u00fcge f\u00fcr einen Sekundenbruchteil \u00fcbereinander und es entsteht der Effekt von verschwimmenden Zahlen. Da der Rest der Ausgabe statisch ist, merkt man dort keinen Unterschied.<\/p>\n<p>Probleme:<\/p>\n<ul>\n<li>Das Script muss Zugriff auf die Portage-Verzeichnisse haben. Root?<\/li>\n<li>Die Ausf\u00fchrung ben\u00f6tigt eine Verbindung zu einem X-Server<\/li>\n<\/ul>\n<p>Ich bin nat\u00fcrlich nicht b\u00f6se wenn jemand die komplette Prozedur in C implementiert und als Hintergrunddienst zur Verf\u00fcgung stellt&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Wie oft stellen sich User wie ich die Frage, wie weit der Compile ist bzw wieviel noch fehlt&#8230; Im Gentoo-Wiki habe ich folgenden C++ L\u00f6sungsansatz gefunden, welchen ich als eprogress.cpp ablege und schliesslich mit g++ compile (g++ eprogress.cpp -o eprogress):<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[39],"class_list":["post-26","post","type-post","status-publish","format-standard","hentry","category-it-related-stuff","tag-gentoo"],"_links":{"self":[{"href":"https:\/\/my.stargazer.at\/de\/wp-json\/wp\/v2\/posts\/26","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/my.stargazer.at\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/my.stargazer.at\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/my.stargazer.at\/de\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/my.stargazer.at\/de\/wp-json\/wp\/v2\/comments?post=26"}],"version-history":[{"count":0,"href":"https:\/\/my.stargazer.at\/de\/wp-json\/wp\/v2\/posts\/26\/revisions"}],"wp:attachment":[{"href":"https:\/\/my.stargazer.at\/de\/wp-json\/wp\/v2\/media?parent=26"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/my.stargazer.at\/de\/wp-json\/wp\/v2\/categories?post=26"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/my.stargazer.at\/de\/wp-json\/wp\/v2\/tags?post=26"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}