void shuffle(string_array *array, int n) { srand(time(NULL)); if (n > 1) { int i; for (i = 0; i < n - 1; i++) { int j = i + rand() / (RAND_MAX / (n - i) + 1); string_swap(array,i,j); } } }
void showhelp(char *source, char *chan, char *args) { struct buffer_block *dyn = NULL; char buffer[512], word[80], *ptr; int i, l, index = 0, found = 0, file, linecount = 0; if (CurrentSendQ > HIGHSENDQTHRESHOLD) { notice(source, "Cannot process your request at this time. Try again later."); return; } GetWord(0, args, word); if (!*word) strcpy(word, "help"); listinit(); /* find the command index */ for (i = 0; i <= N; i++) { if (!strcasecmp(word, commands[i].name)) { found = 1; index = i; break; } else if (!strncasecmp(word, commands[i].name, strlen(word))) { found++; index = i; } } if (found > 1) { sprintf(buffer, "%s is ambiguous", word); notice(source, buffer); return; } else if (found == 0) { if (!strcasecmp(word, "INFO")) { sprintf(buffer, "%s/INFO", HELP_DIR); } else if (!strcasecmp(word, "FORM")) { sprintf(buffer, "%s/FORM", HELP_DIR); } else { sprintf(buffer, "No help on %s. Please use " "showcommands to get a list of commands " "available to you", word); notice(source, buffer); return; } } else { sprintf(buffer, "%s/%s", HELP_DIR, commands[index].file); } alarm(2); file = open(buffer, O_RDONLY); alarm(0); if (file < 0) { if (found) sprintf(buffer, "The help file for command %s " "is not available", commands[index].name); else sprintf(buffer, "This help file is not available"); notice(source, buffer); return; } if (found) { sprintf(buffer, " HELP on %-20s Minimum access: %4d ", commands[index].name, commands[index].Access); notice(source, buffer); } alarm(3); while ((l = read(file, buffer, 511)) > 0) { copy_to_buffer(&dyn, buffer, l); } alarm(0); close(file); while (dyn != NULL) { copy_from_buffer(&dyn, buffer, '\n', 199); if ((ptr = strchr(buffer, '\n')) != NULL) *ptr = '\0'; else continue; if (*buffer == '\0') strcpy(buffer, " "); string_swap(buffer, 512, "$NICK", mynick); string_swap(buffer, 512, "$SERVER", SERVERNAME); notice(source, buffer); linecount++; } if (linecount > 0) CheckFloodFlood(source, linecount); }