Преглед изворни кода

* Moved dumplots() to dccutil.c
* Misc code cleanups


svn: 1933

Bryan Drewery пре 21 година
родитељ
комит
93b7df34ce
4 измењених фајлова са 68 додато и 68 уклоњено
  1. 50 0
      src/dccutil.c
  2. 1 0
      src/dccutil.h
  3. 17 67
      src/misc.c
  4. 0 1
      src/misc.h

+ 50 - 0
src/dccutil.c

@@ -145,6 +145,56 @@ colorbuf(char *buf, size_t len, int idx)
   strcpy(buf, buf3);
 }
 
+/* Dump a potentially super-long string of text.
+ */
+void dumplots(int idx, const char *prefix, char *data)
+{
+  if (!*data) {
+    dprintf(idx, "%s\n", prefix);
+    return;
+  }
+
+  char *p = data, *q = NULL, *n = NULL, c = 0;
+  const size_t max_data_len = 500 - strlen(prefix);
+
+  while (strlen(p) > max_data_len) {
+    q = p + max_data_len;
+    /* Search for embedded linefeed first */
+    n = strchr(p, '\n');
+    if (n && n < q) {
+      /* Great! dump that first line then start over */
+      *n = 0;
+      dprintf(idx, "%s%s\n", prefix, p);
+      *n = '\n';
+      p = n + 1;
+    } else {
+      /* Search backwards for the last space */
+      while (*q != ' ' && q != p)
+        q--;
+      if (q == p)
+        q = p + max_data_len;
+      c = *q;
+      *q = 0;
+      dprintf(idx, "%s%s\n", prefix, p);
+      *q = c;
+      p = q;
+      if (c == ' ')
+        p++;
+    }
+  }
+  /* Last trailing bit: split by linefeeds if possible */
+  n = strchr(p, '\n');
+  while (n) {
+    *n = 0;
+    dprintf(idx, "%s%s\n", prefix, p);
+    *n = '\n';
+    p = n + 1;
+    n = strchr(p, '\n');
+  }
+  if (*p)
+    dprintf(idx, "%s%s\n", prefix, p);  /* Last trailing bit */
+}
+
 void
 dprintf(int idx, const char *format, ...)
 {

+ 1 - 0
src/dccutil.h

@@ -28,6 +28,7 @@ struct portmap {
 
 
 void init_dcc(void);
+void dumplots(int, const char *, char *);
 void dprintf(int, const char *, ...) __attribute__((format(printf, 2, 3)));
 void chatout(const char *, ...) __attribute__((format(printf, 1, 2)));
 void chanout_but(int, int, const char *, ...) __attribute__((format(printf, 3, 4)));

+ 17 - 67
src/misc.c

@@ -270,55 +270,6 @@ void maskhost(const char *s, char *nw)
   }
 }
 
-/* Dump a potentially super-long string of text.
- */
-void dumplots(int idx, const char *prefix, char *data)
-{
-  if (!*data) {
-    dprintf(idx, "%s\n", prefix);
-    return;
-  }
-
-  char *p = data, *q = NULL, *n = NULL, c = 0;
-  const size_t max_data_len = 500 - strlen(prefix);
-
-  while (strlen(p) > max_data_len) {
-    q = p + max_data_len;
-    /* Search for embedded linefeed first */
-    n = strchr(p, '\n');
-    if (n && n < q) {
-      /* Great! dump that first line then start over */
-      *n = 0;
-      dprintf(idx, "%s%s\n", prefix, p);
-      *n = '\n';
-      p = n + 1;
-    } else {
-      /* Search backwards for the last space */
-      while (*q != ' ' && q != p)
-	q--;
-      if (q == p)
-	q = p + max_data_len;
-      c = *q;
-      *q = 0;
-      dprintf(idx, "%s%s\n", prefix, p);
-      *q = c;
-      p = q;
-      if (c == ' ')
-	p++;
-    }
-  }
-  /* Last trailing bit: split by linefeeds if possible */
-  n = strchr(p, '\n');
-  while (n) {
-    *n = 0;
-    dprintf(idx, "%s%s\n", prefix, p);
-    *n = '\n';
-    p = n + 1;
-    n = strchr(p, '\n');
-  }
-  if (*p)
-    dprintf(idx, "%s%s\n", prefix, p);	/* Last trailing bit */
-}
 
 /* Convert an interval (in seconds) to one of:
  * "19 days ago", "1 day ago", "18:12"
@@ -397,7 +348,7 @@ void show_banner(int idx)
     dumplots(-dcc[idx].sock, "", wbanner()); 
   dprintf(idx, " \n");
   dprintf(-dcc[idx].sock,     " ------------------------------------------------------- \n");
-  dprintf(-dcc[idx].sock, STR("| Contributions welcomed by paypal: bryan@shatow.net |\n"));
+  dprintf(_dcc[idx].sock  STR("|             - paypal: bryan@shatow.net  -             |\n"));
   dprintf(-dcc[idx].sock, STR("|             - http://wraith.shatow.net/ -             |\n"));
   dprintf(-dcc[idx].sock,     " ------------------------------------------------------- \n");
   dprintf(idx, " \n");
@@ -487,7 +438,7 @@ void make_rand_str(char *s, size_t len)
       s[j] = 'a' + randint(26);
   }
 
-  if (s[0] == '+' || s[0] == '-')
+  if (strchr(BADPASSCHARS, s[0]))
     s[0] = 'a' + randint(26);
 
   s[len] = '\0';
@@ -531,20 +482,6 @@ char *str_escape(const char *str, const char divc, const char mask)
   return buf;
 }
 
-/* Is every character in a string a digit? */
-int str_isdigit(const char *str)
-{
-  if (!str || (str && !*str))
-    return 0;
-
-  for(; *str; ++str) {
-    if (!egg_isdigit(*str))
-      return 0;
-  }
-  return 1;
-}
-
-
 /* Search for a certain character 'div' in the string 'str', while
  * ignoring escaped characters prefixed with 'mask'.
  *
@@ -592,6 +529,19 @@ void str_unescape(char *str, register const char esc_char)
   return;
 }
 
+/* Is every character in a string a digit? */
+int str_isdigit(const char *str)
+{
+  if (!str || (str && !*str))
+    return 0;
+
+  for(; *str; ++str) {
+    if (!egg_isdigit(*str))
+      return 0;
+  }
+  return 1;
+}
+
 /* Kills the bot. s1 is the reason shown to other bots, 
  * s2 the reason shown on the partyline. (Sup 25Jul2001)
  */
@@ -958,10 +908,10 @@ void showhelp(int idx, struct flag_record *flags, char *string)
 /* Arrange the N elements of ARRAY in random order. */
 void shuffleArray(char *array[], size_t n)
 {
-  size_t j = 0;
+  size_t j = 0, i;
   char *temp = NULL;
 
-  for (size_t i = 0; i < n; i++) {
+  for (i = 0; i < n; i++) {
     j = i + random() / (RAND_MAX / (n - i) + 1);
     temp = array[j];
     array[j] = array[i];

+ 0 - 1
src/misc.h

@@ -33,7 +33,6 @@ int remove_crlf_r(char *);
 char *newsplit(char **);
 char *splitnick(char **);
 void stridx(char *, char *, int);
-void dumplots(int, const char *, char *);
 void daysago(time_t, time_t, char *);
 void days(time_t, time_t, char *);
 void daysdur(time_t, time_t, char *);