コード例 #1
0
void DS_SFX_Load(sfxbuffer_t* buf, struct sfxsample_s* sample)
{
    if(!buf || !sample) return;

    // Does the buffer already have a sample loaded?
    if(buf->sample)
    {
        // Is the same one?
        if(buf->sample->id == sample->id)
            return; // No need to reload.
    }

    // Make sure its not bound right now.
    alSourcei(SRC(buf), AL_BUFFER, 0);

    alBufferData(BUF(buf),
                 sample->bytesPer == 1 ? AL_FORMAT_MONO8 : AL_FORMAT_MONO16,
                 sample->data, sample->size, sample->rate);

    if(DSOPENAL_ERRCHECK(alGetError()))
    {
        /// @todo What to do?
    }
    buf->sample = sample;
}
コード例 #2
0
void DS_SFX_DestroyBuffer(sfxbuffer_t* buf)
{
    ALuint srcName, bufName;

    if(!buf) return;

    srcName = SRC(buf);
    bufName = BUF(buf);

    alDeleteSources(1, &srcName);
    alDeleteBuffers(1, &bufName);

    Z_Free(buf);
}
コード例 #3
0
ファイル: prog_flash.c プロジェクト: KarenHung/ecosgit
void
write_sector(int num, char *buf)
{
    int i, cnt;
    volatile char *wrt = (volatile char *)&FLASH[num*sector_size];

//    diag_printf("Writing to %08x\n", wrt);
    // Enter Program Mode
    FLASH[SEQ_ADD1] = START_CMD1;
    FLASH[SEQ_ADD2] = START_CMD2;
    FLASH[SEQ_ADD1] = PROG_CMD;

    // Note: write bytes as longs regardless of bus width
    for (i = 0;  i < sector_size;  i++) {
        wrt[i] = BUF(i);
    }

    // Wait for sector to program
    cnt = 0;
    i = sector_size - 1;
    while (wrt[i] != BUF(i)) {
        if (cnt++ > 0x01000000) break;
    }
//    diag_printf("Out - i: %d, wrt[i] = %08X.%08X, BUF(i) = %08X, count = %x\n", i, &wrt[i], wrt[i], BUF(i), cnt);

    // Verify
    for (i = 0;  i < sector_size;  i++) {
        for (cnt = 0;  cnt < 10;  cnt++) {
            if (wrt[i] == BUF(i)) break;
            cyg_thread_delay(1);
        }
        if (cnt == 10) {
            diag_printf("Can't program at 0x%08X: %02X not %02X\n", wrt, *wrt, BUF(0));
        }
    }
}
コード例 #4
0
void DS_SFX_Play(sfxbuffer_t* buf)
{
    ALuint source;

    // Playing is quite impossible without a sample.
    if(!buf || !buf->sample) return;

    source = SRC(buf);
    alSourcei(source, AL_BUFFER, BUF(buf));
    alSourcei(source, AL_LOOPING, (buf->flags & SFXBF_REPEAT) != 0);
    alSourcePlay(source);
    DSOPENAL_ERRCHECK(alGetError());

    // The buffer is now playing.
    buf->flags |= SFXBF_PLAYING;
}
コード例 #5
0
/**!
 *  The function loads ASCII file header and tries to identify the type of the
 *header.
 *  Possible types are
 *  SPE, PAR or PHS
 *
 *  if none three above identified, returns "undefined" type
 *  it also returns the FileTypeDescriptor, which identifyes the position of the
 *data in correcponding ASCII file
 *  plus characteristics of the data extracted from correspondent data header.
*/
FileTypeDescriptor
FindDetectorsPar::get_ASCII_header(std::string const &fileName,
                                   std::ifstream &data_stream) {
  std::vector<char> BUF(1024);
  FileTypeDescriptor file_descriptor;
  file_descriptor.Type = NumFileTypes; // set the autotype to invalid

  data_stream.open(fileName.c_str(), std::ios_base::in | std::ios_base::binary);
  if (!data_stream.is_open()) {
    g_log.error() << " can not open existing ASCII data file: " << fileName
                  << std::endl;
    throw(Kernel::Exception::FileError(" Can not open existing input data file",
                                       fileName));
  }
  // let's identify the EOL symbol; As the file may have been prepared on
  // different OS, from where you are reading it
  // and no conversion have been performed;
  char symbol;
  data_stream.get(symbol);
  while (symbol > 0x1F) {
    data_stream.get(symbol);
  }
  char EOL;
  if (symbol == 0x0D) { // Win or old Mac file
    data_stream.get(symbol);
    if (symbol == 0x0A) { // Windows file
      EOL = 0x0A;
    } else { // Mac
      EOL = 0x0D;
      data_stream.putback(symbol);
    }
  } else if (symbol == 0x0A) { // unix file.
    EOL = 0x0A;
  } else {
    g_log.error()
        << " Error reading the first row of the input ASCII data file: "
        << fileName << " as it contains unprintable characters\n";
    throw(Kernel::Exception::FileError(" Error reading the first row of the "
                                       "input ASCII data file, as it contains "
                                       "unprintable characters",
                                       fileName));
  }

  file_descriptor.line_end = EOL;
  data_stream.seekg(0, std::ios::beg);

  get_my_line(data_stream, &BUF[0], BUF.size(), EOL);
  if (!data_stream.good()) {
    g_log.error() << " Error reading the first row of the input data file "
                  << fileName << ", It may be bigger then 1024 symbols\n";
    throw(Kernel::Exception::FileError(" Error reading the first row of the "
                                       "input data file, It may be bigger then "
                                       "1024 symbols",
                                       fileName));
  }

  // let's find if there is one or more groups of symbols inside of the buffer;
  int space_to_symbol_change = count_changes(&BUF[0], BUF.size());
  if (space_to_symbol_change >
      1) { // more then one group of symbols in the string, spe file
    int nData_records(0), nData_blocks(0);
    // cppcheck-suppress invalidscanf
    int nDatas = sscanf(&BUF[0], " %d %d ", &nData_records, &nData_blocks);
    file_descriptor.nData_records = (size_t)nData_records;
    file_descriptor.nData_blocks = (size_t)nData_blocks;
    if (nDatas != 2) {
      g_log.error() << " File " << fileName << " iterpreted as SPE but does "
                                               "not have two numbers in the "
                                               "first row\n";
      throw(Kernel::Exception::FileError(" File iterpreted as SPE but does not "
                                         "have two numbers in the first row",
                                         fileName));
    }
    file_descriptor.Type = SPE_type;
    get_my_line(data_stream, &BUF[0], BUF.size(), EOL);
    if (BUF[0] != '#') {
      g_log.error()
          << " File " << fileName
          << "iterpreted as SPE does not have symbol # in the second row\n";
      throw(Kernel::Exception::FileError(
          " File iterpreted as SPE does not have symbol # in the second row",
          fileName));
    }
    file_descriptor.data_start_position =
        data_stream.tellg(); // if it is SPE file then the data begin after the
                             // second line;
  } else {
    file_descriptor.data_start_position =
        data_stream.tellg(); // if it is PHX or PAR file then the data begin
                             // after the first line;
    file_descriptor.nData_records = atoi(&BUF[0]);
    file_descriptor.nData_blocks = 0;

    // let's ifendify now if is PHX or PAR file;
    data_stream.getline(&BUF[0], BUF.size(), EOL);

    int space_to_symbol_change = count_changes(&BUF[0], BUF.size());
    if (space_to_symbol_change == 6 ||
        space_to_symbol_change == 5) { // PAR file
      file_descriptor.Type = PAR_type;
      file_descriptor.nData_blocks = space_to_symbol_change;
    } else if (space_to_symbol_change == 7) { // PHX file
      file_descriptor.Type = PHX_type;
      file_descriptor.nData_blocks = space_to_symbol_change;
    } else { // something unclear or damaged
      g_log.error() << " can not identify format of the input data file "
                    << fileName << std::endl;
      throw(Kernel::Exception::FileError(
          " can not identify format of the input data file", fileName));
    }
  }
  return file_descriptor;
}
コード例 #6
0
ファイル: pyfcgi.c プロジェクト: msolo-dropbox/msolo
/*
 * Internal function to read a line
 * XXX: does not check for a valid stream,
 * the caller is responsible for that!
 *
 * - if bytesrequested is 0, an empty string is returned
 * - if bytesrequested > 0, it is treated as the max
 *   length of the line to return
 * - if bytesrequested < 0, an arbitrary length line
 *   is returned
 *
 */
static PyObject *
get_line(fcgi_Stream *self, long bytesrequested)
{
    FCGX_Stream *s;
    size_t bytesread, buffersize;
    PyObject *v;
    int c, done;

    s = *(self->s);

    if (bytesrequested == 0)
        return PyString_FromString("");

    if (bytesrequested < 0)
        buffersize = new_buffersize((size_t)0);
    else
        buffersize = bytesrequested;

    if (buffersize > INT_MAX) {
        PyErr_SetString(PyExc_OverflowError,
          "requested number of bytes is more than a Python string can hold");
        return NULL;
    }

    v = PyString_FromStringAndSize((char *)NULL, buffersize);
    if (v == NULL)
        return NULL;

    bytesread = 0;
    done = 0;

    for(;;) {
        Py_BEGIN_ALLOW_THREADS
        while (buffersize - bytesread > 0) {
            c = FCGX_GetChar(s);
            if (c == EOF) {
                if (bytesread == 0) {
                    Py_BLOCK_THREADS
                    Py_DECREF(v);
                    return PyString_FromString("");
                } else {
                    done = 1;
                    break;
                }
            }

            *(BUF(v) + bytesread) = (char) c;
            bytesread++;

            if (c == '\n') {
                done = 1;
                break;
            }
        }
        Py_END_ALLOW_THREADS
	if (done || (bytesread == bytesrequested))
            break;

        if (bytesrequested < 0) {
            buffersize = new_buffersize(buffersize);
            if (_PyString_Resize(&v, buffersize) < 0)
                return NULL;
        }
    }

    if (bytesread != buffersize)
        _PyString_Resize(&v, bytesread);

    return v;
}
コード例 #7
0
ファイル: pyfcgi.c プロジェクト: msolo-dropbox/msolo
static PyObject *
fcgi_Stream_read(fcgi_Stream *self, PyObject *args)
{
    FCGX_Stream *s;
    long bytesrequested = -1;
    size_t bytesread, buffersize, chunksize;
    PyObject *v;

    fcgi_Stream_Check();

    s = *(self->s);

    if (!PyArg_ParseTuple(args, "|l:read", &bytesrequested))
        return NULL;

    if (bytesrequested == 0)
        return PyString_FromString("");

    if (bytesrequested < 0)
        buffersize = new_buffersize((size_t)0);
    else
        buffersize = bytesrequested;

    if (buffersize > INT_MAX) {
        PyErr_SetString(PyExc_OverflowError,
          "requested number of bytes is more than a Python string can hold");
        return NULL;
    }

    v = PyString_FromStringAndSize((char *)NULL, buffersize);
    if (v == NULL)
        return NULL;

    bytesread = 0;

    for (;;) {
        Py_BEGIN_ALLOW_THREADS
        chunksize = FCGX_GetStr(BUF(v) + bytesread, buffersize - bytesread, s);
        Py_END_ALLOW_THREADS

        if (chunksize == 0) {
            if (FCGX_HasSeenEOF(s))
                break;
            PyErr_SetString(PyExc_IOError, "Read failed");
            Py_DECREF(v);
            return NULL;
        }

        bytesread += chunksize;
        if (bytesread < buffersize) {
            break;
        }

        if (bytesrequested < 0) {
            buffersize = new_buffersize(buffersize);
            if (_PyString_Resize(&v, buffersize) < 0)
                return NULL;
        } else {
            /* Got what was requested. */
            break;
        }
    }

    if (bytesread != buffersize)
        _PyString_Resize(&v, bytesread);

    return v;
}
コード例 #8
0
ファイル: stdio.c プロジェクト: conmarap/dart
static int intern_printf(char *buf, size_t sz, 
              const char *fmt, va_list ap)
{
    char conv_buf[32];
    char *str;
    int i, slen;
    const char *fstart = 0;

    /* state */
    int cnum = 0;
    int base = 10;
    int alt = 0;
    int fwidth = 0;
    int padc = ' ';
    int sign = 0;
    int left_align = 0; /* not implemented yet */
    int hex_caps = 0;
    int unsig = 0;

    while(*fmt)
    {
        if(*fmt == '%') 
        {
            fstart = fmt++;
            continue;
        }

        if(fstart) 
        {
            if(IS_CONV(*fmt)) 
            {
                switch(*fmt) 
                {
                    case 'X':
                        hex_caps = 1;

                    case 'x':
                    case 'p':
                        base = 16;

                        if(alt) 
                        {
                            bwrite(BUF(buf), SZ(sz), "0x", 2);
                        }

                    case 'u':
                        unsig = 1;

                        if(0)
                        {
                    case 'o':
                            base = 8;

                            if(alt) 
                            {
                                bwrite(BUF(buf), SZ(sz), "0", 1);
                            }
                        }

                    case 'd':
                    case 'i':
                        if(unsig)
                        {
                            utoa(va_arg(ap, unsigned int), conv_buf, base);
                        } 
                        else 
                        {
                            itoa(va_arg(ap, int), conv_buf, base);
                        }
                        if(hex_caps) 
                        {
                            for(i=0; conv_buf[i]; i++) 
                            {
                                conv_buf[i] = toupper(conv_buf[i]);
                            }
                        }

                        slen = strlen(conv_buf);
                        for(i=slen; i<fwidth; i++) 
                        {
                            bwrite(BUF(buf), SZ(sz), (char*)&padc, 1);
                            cnum++;
                        }
    
                        bwrite(BUF(buf), SZ(sz), conv_buf, strlen(conv_buf));
                        cnum += slen;
                        break;

                    case 'c':
                    {
                        char c = va_arg(ap, int);
                        bwrite(BUF(buf), SZ(sz), &c, 1);
                        cnum++;
                    }
                    break;

                case 's':
                    str = va_arg(ap, char*);
                    slen = strlen(str);

                    for(i=slen; i<fwidth; i++) {
                        bwrite(BUF(buf), SZ(sz), (char*)&padc, 1);
                        cnum++;
                    }
                    bwrite(BUF(buf), SZ(sz), str, slen);
                    cnum += slen;
                    break;

                case 'n':
                    *va_arg(ap, int*) = cnum;
                    break;

                default:
                    break;
                }

                /* restore default conversion state */
                base = 10;
                alt = 0;
                fwidth = 0;
                padc = ' ';
                hex_caps = 0;

                fstart = 0;
                fmt++;
            } 
            else 
            {
                switch(*fmt) 
                {
                    case '#':
                        alt = 1;
                        break;

                    case '+':
                        sign = 1;
                        break;
    
                    case '-':
                        left_align = 1;
                        break;
    
                    case 'l':
                    case 'L':
                        break;
    
                    case '0':
                        padc = '0';
                        break;

                    default:
                        if(isdigit(*fmt)) 
                        {
                            const char *fw = fmt;
                            while(*fmt && isdigit(*fmt)) fmt++;
    
                            fwidth = atoi(fw);
                            continue;
                        }
                    }
                    fmt++;
                }
            } 
            else 
            {
コード例 #9
0
ファイル: stdio.c プロジェクト: conmarap/dart
                    default:
                        if(isdigit(*fmt)) 
                        {
                            const char *fw = fmt;
                            while(*fmt && isdigit(*fmt)) fmt++;
    
                            fwidth = atoi(fw);
                            continue;
                        }
                    }
                    fmt++;
                }
            } 
            else 
            {
                bwrite(BUF(buf), SZ(sz), (char*)fmt++, 1);
                cnum++;
            }
        }
        return 0;
}


/* bwrite is called by intern_printf to transparently handle writing into a
 * buffer (if buf is non-null) or to the terminal (if buf is null).
 */
static void bwrite(char *buf, size_t buf_sz, char *str, int sz)
{
    if(buf) 
    {
        if(buf_sz && buf_sz <= sz) sz = buf_sz - 1;
コード例 #10
0
ファイル: uip_arp.c プロジェクト: CurieBSP/zephyr
/*-----------------------------------------------------------------------------------*/
void
uip_arp_out(struct net_buf *buf)
{
  struct arp_entry *tabptr = arp_table;

  /* Find the destination IP address in the ARP table and construct
     the Ethernet header. If the destination IP addres isn't on the
     local network, we use the default router's IP address instead.

     If not ARP table entry is found, we overwrite the original IP
     packet with an ARP request for the IP address. */

  /* First check if destination is a local broadcast. */
  if(uip_ipaddr_cmp(&IPBUF(buf)->destipaddr, &uip_broadcast_addr)) {
    memcpy(IPBUF(buf)->ethhdr.dest.addr, broadcast_ethaddr.addr, 6);
  } else if(IPBUF(buf)->destipaddr.u8[0] == 224) {
    /* Multicast. */
    IPBUF(buf)->ethhdr.dest.addr[0] = 0x01;
    IPBUF(buf)->ethhdr.dest.addr[1] = 0x00;
    IPBUF(buf)->ethhdr.dest.addr[2] = 0x5e;
    IPBUF(buf)->ethhdr.dest.addr[3] = IPBUF(buf)->destipaddr.u8[1];
    IPBUF(buf)->ethhdr.dest.addr[4] = IPBUF(buf)->destipaddr.u8[2];
    IPBUF(buf)->ethhdr.dest.addr[5] = IPBUF(buf)->destipaddr.u8[3];
  } else {
    /* Check if the destination address is on the local network. */
    if(!uip_ipaddr_maskcmp(&IPBUF(buf)->destipaddr, &uip_hostaddr, &uip_netmask)) {
      /* Destination address was not on the local network, so we need to
	 use the default router's IP address instead of the destination
	 address when determining the MAC address. */
      uip_ipaddr_copy(&ipaddr, &uip_draddr);
    } else {
      /* Else, we use the destination IP address. */
      uip_ipaddr_copy(&ipaddr, &IPBUF(buf)->destipaddr);
    }
    for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
      if(uip_ipaddr_cmp(&ipaddr, &tabptr->ipaddr)) {
	break;
      }
	  tabptr++;
    }

    if(i == UIP_ARPTAB_SIZE) {
      /* The destination address was not in our ARP table, so we
	 overwrite the IP packet with an ARP request. */

      memset(BUF(buf)->ethhdr.dest.addr, 0xff, 6);
      memset(BUF(buf)->dhwaddr.addr, 0x00, 6);
      memcpy(BUF(buf)->ethhdr.src.addr, uip_lladdr.addr, 6);
      memcpy(BUF(buf)->shwaddr.addr, uip_lladdr.addr, 6);

      uip_ipaddr_copy(&BUF(buf)->dipaddr, &ipaddr);
      uip_ipaddr_copy(&BUF(buf)->sipaddr, &uip_hostaddr);
      BUF(buf)->opcode = UIP_HTONS(ARP_REQUEST); /* ARP request. */
      BUF(buf)->hwtype = UIP_HTONS(ARP_HWTYPE_ETH);
      BUF(buf)->protocol = UIP_HTONS(UIP_ETHTYPE_IP);
      BUF(buf)->hwlen = 6;
      BUF(buf)->protolen = 4;
      BUF(buf)->ethhdr.type = UIP_HTONS(UIP_ETHTYPE_ARP);

      uip_appdata(buf) = &uip_buf(buf)[UIP_TCPIP_HLEN + UIP_LLH_LEN];

      uip_len(buf) = sizeof(struct arp_hdr);
      return;
    }

    /* Build an ethernet header. */
    memcpy(IPBUF(buf)->ethhdr.dest.addr, tabptr->ethaddr.addr, 6);
  }
  memcpy(IPBUF(buf)->ethhdr.src.addr, uip_lladdr.addr, 6);

  IPBUF(buf)->ethhdr.type = UIP_HTONS(UIP_ETHTYPE_IP);

  uip_len(buf) += sizeof(struct uip_eth_hdr);
}
コード例 #11
0
ファイル: uip_arp.c プロジェクト: CurieBSP/zephyr
/*-----------------------------------------------------------------------------------*/
void
uip_arp_arpin(struct net_buf *buf)
{

  if(uip_len(buf) < sizeof(struct arp_hdr)) {
    uip_len(buf) = 0;
    return;
  }
  uip_len(buf) = 0;

  switch(BUF(buf)->opcode) {
  case UIP_HTONS(ARP_REQUEST):
    /* ARP request. If it asked for our address, we send out a
       reply. */
    /*    if(BUF->dipaddr[0] == uip_hostaddr[0] &&
	  BUF->dipaddr[1] == uip_hostaddr[1]) {*/
    PRINTF("uip_arp_arpin: request for %d.%d.%d.%d (we are %d.%d.%d.%d)\n",
	   BUF(buf)->dipaddr.u8[0], BUF(buf)->dipaddr.u8[1],
	   BUF(buf)->dipaddr.u8[2], BUF(buf)->dipaddr.u8[3],
	   uip_hostaddr.u8[0], uip_hostaddr.u8[1],
	   uip_hostaddr.u8[2], uip_hostaddr.u8[3]);
    if(uip_ipaddr_cmp(&BUF(buf)->dipaddr, &uip_hostaddr)) {
      /* First, we register the one who made the request in our ARP
	 table, since it is likely that we will do more communication
	 with this host in the future. */
      uip_arp_update(&BUF(buf)->sipaddr, &BUF(buf)->shwaddr);

      BUF(buf)->opcode = UIP_HTONS(ARP_REPLY);

      memcpy(BUF(buf)->dhwaddr.addr, BUF(buf)->shwaddr.addr, 6);
      memcpy(BUF(buf)->shwaddr.addr, uip_lladdr.addr, 6);
      memcpy(BUF(buf)->ethhdr.src.addr, uip_lladdr.addr, 6);
      memcpy(BUF(buf)->ethhdr.dest.addr, BUF(buf)->dhwaddr.addr, 6);

      uip_ipaddr_copy(&BUF(buf)->dipaddr, &BUF(buf)->sipaddr);
      uip_ipaddr_copy(&BUF(buf)->sipaddr, &uip_hostaddr);

      BUF(buf)->ethhdr.type = UIP_HTONS(UIP_ETHTYPE_ARP);
      uip_len(buf) = sizeof(struct arp_hdr);
    }
    break;
  case UIP_HTONS(ARP_REPLY):
    /* ARP reply. We insert or update the ARP table if it was meant
       for us. */
    if(uip_ipaddr_cmp(&BUF(buf)->dipaddr, &uip_hostaddr)) {
      uip_arp_update(&BUF(buf)->sipaddr, &BUF(buf)->shwaddr);
    }
    break;
  }

  return;
}