Exemple #1
0
/*
 * Internal form of read()/xread().
 */
static int
iread(u_char *buf, size_t len,
      void (*copyfun)(const void *src, void *dst, size_t size))
{
	u_int32_t newblk, ptr;
	size_t bsize;

	newblk = offset / BLKSIZE + startblk;

	if (newblk != curblk) {
		if (offset + len >= filesize) {
			badread("access beyond file limit", newblk);
			return -1;
		}
		if (bread(newblk, 1, xbuf)) {
			badread("BIOS read error", newblk);
			return -1;
		}
		curblk = newblk;
	}
	ptr = offset & (BLKSIZE - 1);
	if (ptr > 0) {
		/* initial short transfer */
		bsize = minlen(BLKSIZE - ptr, len);
		copyfun(xbuf + ptr, buf, bsize);
		buf += bsize;
		len -= bsize;
		offset += bsize;
	}
	for (; len > 0; len -= bsize) {
		bsize = minlen(len, BLKSIZE);
		newblk = offset / BLKSIZE + startblk;

		if (newblk != curblk) {
			if (offset + bsize > filesize) {
				badread("access beyond file limit", newblk);
				return -1;
			}
			if (bread(newblk, 1, xbuf)) {
				badread("BIOS read error", newblk);
				return -1;
			}
			curblk = newblk;
		}
		copyfun(xbuf, buf, bsize);
		buf += bsize;
		offset += bsize;
	}
	return 0;
}
Exemple #2
0
void functions (char * text[], int linesNum){
    char c [80], k [80];
    char * ptr = &c;
    int i, j = 0, l = 0, number;
    int white_text = FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE |FOREGROUND_INTENSITY;
    help (linesNum);
    PosColor (5, 7 + linesNum, white_text);
    printf ("Please, enter the needed function without a number\n\n     HERE>> ");
    gets (c);
    for (i = 0; i < 80; i++){
        if (c[i] != ' '){
          k[j] = c[i];
          j++;
          l = 1;
        }
        if (c[i] == ' ' && l == 1){
          k[j] = c[i];
          j++;
          k[j] = 0;
          break;
        }
    }
    if (strcmp(k, "random") == 0  || strcmp(k, "shorterthan") == 0 || strcmp(k, "longerthan") == 0){
        printf ("Enter the number >> ");
        scanf ("%i", &number);
        printf ("\n");
        printf ("%i", number);
    }
    clearaftertable (linesNum);
    if (strcmp(k, "help") == 0){
            help (linesNum);
    } else
      if (strcmp(k, "exit") == 0){
          PosColor (0,0,0);
          system ("cls");
          getch();
          initRectf();
    } else
      if (strcmp(k, "length") == 0){
          lenofstrings (text, linesNum);
    } else
      if (strcmp(k, "longest") == 0){
            maxlen (text, linesNum);

    }
      if (strcmp(k, "shortest") == 0){
          minlen (text, linesNum);
    }
      if (strcmp(k, "random") == 0){
        randomletters(text, linesNum, number);
    }
      if (strcmp(k, "swap") == 0){
        change (text, linesNum);

    }
      if (strcmp(k, "shorterthan") == 0){
        findlessthan (text, linesNum, number);
    }
      if (strcmp(k, "longerthan") == 0){
        findmorethan (text, linesNum, number);
    }
      if (strcmp(k, "numberofwords") == 0){
        wordcount (text, linesNum);
    }
      if (strcmp(k, "integer") == 0){
            findNumInAllStrings(text, linesNum);

    }
     functions(text, linesNum);
}