Ejemplo n.º 1
0
void parse_config(char *filename, struct conf *conf) {
    int conf_file = open(filename, O_RDONLY);

    char buffer[DFINGER_BUFFER_SIZE];
    memset(buffer, 0, DFINGER_BUFFER_SIZE);
    char line[DFINGER_LINE_SIZE];
    memset(line, 0, DFINGER_LINE_SIZE);
    size_t blen = DFINGER_BUFFER_SIZE;
    size_t boffset = 0;
    size_t llen = DFINGER_LINE_SIZE;

    int ret;
    int num_read;
    while ((num_read = read(conf_file, buffer, DFINGER_BUFFER_SIZE) > 0)) {
        blen += num_read;
        while ((ret = fetch_line(buffer, blen, &boffset, line, llen)) !=
                RTL_WANT_MORE) {
            switch (ret) {
            case RTL_LINE_FETCHED:
                set_option(line, conf);
                break;
            case RTL_BLANK_LINE:
                break;
            default:
                return;
            }
        }
        move_buffer(buffer, blen, &boffset);
    }

    close(conf_file);
}
Ejemplo n.º 2
0
STATIC struct buffer FAR *searchblock(ULONG blkno, COUNT dsk)
{
  int fat_count = 0;
  struct buffer FAR *bp;
  size_t lastNonFat = 0;
  size_t uncacheBuf = 0;
  seg bufseg = FP_SEG(firstbuf);
  size_t firstbp = FP_OFF(firstbuf);

#ifdef DISPLAY_GETBLOCK
  printf("[searchblock %d, blk %ld, buf ", dsk, blkno);
#endif

  /* Search through buffers to see if the required block  */
  /* is already in a buffer                               */

  bp = MK_FP(bufseg, firstbp);
  do
  {
    if ((bp->b_blkno == blkno) &&
        (bp->b_flag & BFR_VALID) && (bp->b_unit == dsk))
    {
      /* found it -- rearrange LRU links      */
#ifdef DISPLAY_GETBLOCK
      printf("HIT %04x:%04x]\n", FP_SEG(bp), FP_OFF(bp));
#endif
      bp->b_flag &= ~BFR_UNCACHE;  /* reset uncache attribute */
      if (FP_OFF(bp) != firstbp)
      {
        *(UWORD *)&firstbuf = FP_OFF(bp);
        move_buffer(bp, firstbp);
      }
      return bp;
    }

    if (bp->b_flag & BFR_UNCACHE)
      uncacheBuf = FP_OFF(bp);

    if (bp->b_flag & BFR_FAT)
      fat_count++;
    else
      lastNonFat = FP_OFF(bp);
    bp = b_next(bp);
  } while (FP_OFF(bp) != firstbp);

  /*
     now take either the last buffer in chain (not used recently)
     or, if we are low on FAT buffers, the last non FAT buffer
   */

  if (uncacheBuf)
  {
    bp = bufptr(uncacheBuf);
  }
  else if (bp->b_flag & BFR_FAT && fat_count < 3 && lastNonFat)
  {
    bp = bufptr(lastNonFat);
  }
  else
  {
    bp = b_prev(bufptr(firstbp));
  }

  bp->b_flag |= BFR_UNCACHE;  /* set uncache attribute */

#ifdef DISPLAY_GETBLOCK
  printf("MISS, replace %04x:%04x]\n", FP_SEG(bp), FP_OFF(bp));
#endif

  if (FP_OFF(bp) != firstbp)          /* move to front */
  {
    move_buffer(bp, firstbp);
    *(UWORD *)&firstbuf = FP_OFF(bp);
  }
  return bp;
}
Ejemplo n.º 3
0
/**
 * @brief Newlib hook to allow printf/iprintf to appear on console
 *
 * @param[in] buf
 *            Pointer to data buffer containing the data to write
 * @param[in] len
 *            Length of data in bytes expected to be written
 *
 * @return Number of bytes written
 */
static int __console_write( char *buf, unsigned int len )
{
    int pos = strlen(render_buffer);

    /* Copy over to screen buffer */
    for(int x = 0; x < len; x++)
    {
        if(pos == CONSOLE_WIDTH * CONSOLE_HEIGHT)
        {
            /* Need to scroll the buffer */
            move_buffer();
        }

        switch(buf[x])
        {
            case '\r':
            case '\n':
                /* Add enough space to get to next line */
                if(!(pos % CONSOLE_WIDTH))
                {
                    render_buffer[pos++] = ' ';
                }

                while(pos % CONSOLE_WIDTH)
                {
                    render_buffer[pos++] = ' ';
                }

                /* Make sure we don't run down the end */
                if(pos == CONSOLE_WIDTH * CONSOLE_HEIGHT)
                {
                    move_buffer();
                }

                break;
            case '\t':
                /* Add enough spaces to go to the next tab stop */
                if(!(pos % TAB_WIDTH))
                {
                    render_buffer[pos++] = ' ';
                }

                while(pos % TAB_WIDTH)
                {
                    render_buffer[pos++] = ' ';
                }

                /* Make sure we don't run down the end */
                if(pos == CONSOLE_WIDTH * CONSOLE_HEIGHT)
                {
                    move_buffer();
                }
                break;
            default:
                /* Copy character over */
                render_buffer[pos++] = buf[x];
                break;
        }
    }

    /* Cap off the end! */
    render_buffer[pos] = 0;
    
    /* Out to screen! */
    if(render_now == RENDER_AUTOMATIC)
    {
        __console_render();
    }

    /* Always write all */
    return len;
}