changeset 76:a8f8492abd44

[/trunk] Changeset 90 by mikael * Cleaning * Fix a bug when the log file cannot be opened.
author mikael
date Sat, 16 Apr 2005 18:13:24 +0000
parents ff119bb11563
children 32f54ad6d729
files mcabber/src/screen.c mcabber/src/utils.c
diffstat 2 files changed, 5 insertions(+), 169 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/screen.c	Sat Apr 16 17:14:55 2005 +0000
+++ b/mcabber/src/screen.c	Sat Apr 16 18:13:24 2005 +0000
@@ -185,10 +185,8 @@
   tmp->panel = new_panel(tmp->win);
   tmp->name = (char *) calloc(1, 1024);
   strncpy(tmp->name, title, 1024);
+  scr_clear_box(tmp->win, 0, 0, lines, cols, COLOR_GENERAL);
 
-  //scr_draw_box(tmp->win, 0, 0, lines, cols, COLOR_GENERAL, 0, 0);
-  scr_clear_box(tmp->win, 0, 0, lines, cols, COLOR_GENERAL);
-  //mvwprintw(tmp->win, 0, (cols - (2 + strlen(title))) / 2, " %s ", title);
   if ((!dont_show)) {
     currentWindow = tmp;
   } else {
--- a/mcabber/src/utils.c	Sat Apr 16 17:14:55 2005 +0000
+++ b/mcabber/src/utils.c	Sat Apr 16 18:13:24 2005 +0000
@@ -1,18 +1,18 @@
 #include <stdio.h>
-#include <string.h>
 #include <stdlib.h>
-#include <ncurses.h>
 #include <stdarg.h>
 #include <time.h>
 
 /* Variables globales a UTILS.C */
-int DebugEnabled = 0;
+static int DebugEnabled;
 
 void ut_InitDebug(int level)
 {
   FILE *fp = fopen("/tmp/mcabberlog", "w");
 
   DebugEnabled = level;
+
+  if (!fp) return;
   fprintf(fp, "Debugging mode started...\n"
 	  "-----------------------------------\n");
   fclose(fp);
@@ -27,6 +27,7 @@
 
   if (DebugEnabled) {
     fp = fopen("/tmp/mcabberlog", "a+");
+    if (!fp) return;
     buffer = (char *) calloc(1, 64);
 
     ahora = time(NULL);
@@ -42,166 +43,3 @@
   }
 }
 
-char **ut_SplitMessage(char *message, int *nsubmsgs, unsigned int maxlong)
-{
-  /* BUGs:    recorta la palabra si la longitud maxlong es menor que la palabra
-     //  maxlong = 4
-     // message = "peaso bug!"
-     // submsgs[0] = "peas"
-     // submsgs[1] = "bug!"
-     // por lo demas, rula de arte. De todos modos, podrias verificarla ???
-   */
-  char *running;
-  char *aux;
-  char *aux2;
-  char **submsgs;
-  char *buffer = (char *) malloc(strlen(message) * 2);
-  int maxnlines = 50;
-  int i = 0;
-
-  submsgs = (char **) malloc(maxnlines * sizeof(char *));
-
-  running = strdup(message);
-  aux2 = strdup(message);
-
-  aux = index(running, '\n');     /* is there a CR? */
-
-  while ((strlen(aux2) > maxlong) || (aux)) {
-    memset(buffer, 0, strlen(message) * 2);
-    running[maxlong] = '\0';	    /* cut at $maxlong chars */
-
-    if (aux != NULL) {              /* there is a CR */
-      strncpy(buffer, running, strlen(running) - strlen(aux));
-    } else {
-      aux = rindex(running, ' ');   /* look for last blank */
-      if (aux != NULL)		    /* hay blanco! */
-        strncpy(buffer, running, strlen(running) - strlen(aux));
-      else
-        strcpy(buffer, running);    /* se supone que esto es pa evitar  el bug explicado arriba, pero no rula */
-    }
-
-    submsgs[i] = (char *) malloc(strlen(buffer) + 1);	/*reservamos memoria */
-    strcpy(submsgs[i], buffer);	/*copiamos el buffer de arriba */
-    i++;			/*aumentamos numero de mensajillos */
-    aux2 += strlen(buffer) + 1;	/*eliminamos texto particionado */
-    sprintf(running, "%s", aux2);	/*y lo copiamos de nuevo a la string de "curro" */
-
-    // Check if we have allocated enough space
-    if (i >= maxnlines) {
-      maxnlines += 50;
-      submsgs = (char **) realloc(submsgs, maxnlines * sizeof(char *));
-    }
-    aux = index(running, '\n');     /* is there is a CR now? */
-  }
-  /* last part of the message */
-  if (strlen(aux2) > 0) {
-    submsgs[i] = (char *) malloc(strlen(aux2) + 1);
-    strcpy(submsgs[i], aux2);
-    i++;
-  }
-  (*nsubmsgs) = i;
-  free(buffer);
-  return submsgs;
-}
-
-/* Desc: get the rightmost substring
- *
- * In  : string, match
- * Out : ptr to substring (or NULL if not found)
- *
- * Note: this one has no namespace, cos it belongs to <string.h>
- */
-char *ut_strrstr(const char *s1, const char *s2)
-{
-  int l = strlen(s2);
-
-  if (l) {
-    const char *s = strchr(s1, '\0') - l;
-    while (s >= s1) {
-      if (*s == *s2) {
-	int _l = l - 1;
-	const char *_s = s + 1, *_s2 = s2 + 1;
-	while (_l) {
-	  if (*_s++ != *_s2++) {
-	    break;
-	  }
-	  _l--;
-	}
-	if (!_l) {
-	  return (char *) s;
-	}
-      }
-      s--;
-    }
-  }
-
-  return NULL;
-}
-
-char *gettag(char *buffer, char *what)
-{
-  char *aux;
-  char *aux2;
-  char *result = (char *) malloc(1024);
-  char *tmp = (char *) malloc(1024);
-  memset(result, 0, 1024);
-  memset(tmp, 0, 1024);
-
-  sprintf(tmp, "<%s>", what);
-  aux = strstr(buffer, tmp);
-  if (aux) {
-    aux += strlen(tmp);
-    sprintf(tmp, "</%s>", what);
-    aux2 = strstr(aux, tmp);
-    if (aux2) {
-      strncpy(result, aux, strlen(aux) - strlen(aux2));
-      free(tmp);
-      return result;
-    }
-  }
-  free(tmp);
-  free(result);
-  return "UNKtag";
-}
-
-
-char *getattr(char *buffer, char *what)
-{
-  char *aux;
-  char *aux2;
-  char *result = (char *) malloc(1024);
-  memset(result, 0, 1024);
-
-  aux = strstr(buffer, what);
-  if (aux) {
-    aux += strlen(what);
-    aux2 = strstr(aux, "'");
-    if (aux2) {
-      strncpy(result, aux, strlen(aux) - strlen(aux2));
-      return result;
-    }
-  }
-  free(result);
-  return "UNKattr";
-}
-
-void ut_CenterMessage(char *text, int width, char *output)
-{
-  char *blank;
-  int ntest, nn;
-
-  memset(output, 0, strlen(output));
-
-  ntest = (width - strlen(text)) / 2;
-  blank = (char *) malloc(ntest + 1);
-
-  for (nn = 0; nn < ntest; nn++)
-    blank[nn] = ' ';
-  blank[ntest] = '\0';
-
-  strcpy(output, blank);
-  strcat(output, text);
-  strcat(output, blank);
-
-  free(blank);
-}