Exemplo n.º 1
0
Arquivo: dxl.c Projeto: btolfa/rnv
int dxl_allows(char *typ,char *ps,char *s,int n) {
  int pid,status;

  if(!dxl_cmd) return 0;
  if((pid=fork())==0) {
    char **argv; int argc;
    char *p; int arg, i;

    argc=5; p=ps; arg=0;
    for(;;) {
      if(*p=='\0') {
	if(arg) {arg=0; ++argc;} else break;
      } else arg=1;
      ++p;
    }
    argv=(char**)m_alloc(argc,sizeof(char*));
    argv[--argc]=NULL;
    argv[--argc]=(char*)m_alloc(n+1,sizeof(char)); argv[argc][n]='\0'; strncpy(argv[argc],s,n);
    argv[0]=dxl_cmd; argv[1]="allows"; argv[2]=typ;
    i=3; if(i<argc) {
      for(;;) {
	argv[i++]=ps;
	if(i==argc) break;
	while(*(ps++));
      }
    }
    execv(dxl_cmd,argv);
    (*er_printf)("dxl: cannot execute %s: %s\n",dxl_cmd,strerror(errno));
 } else if(pid>0) {
    wait(&status);
    return !WEXITSTATUS(status);
  }
  (*er_printf)("dxl: %s\n",strerror(errno));
  return 0;
}
Exemplo n.º 2
0
int  readtable0(table*  tab,FILE * txt)
{  
  linelist lastln,newline;                                                     
  int len,i;                                                                   
  linerec zeroline;                                                            
                                                                          
  if(txt==NULL) return 1;                                                      
  cleartab(tab);                                                               
  if(!fgets1(tab->mdlName,STRSIZ,txt)) return 1;                                             
  if(!fgets1(tab->headln,70,txt))return 1;                                                  
  if(!fgets1(tab->format,STRSIZ,txt))return 1;                                              
  len=strlen(tab->format);                                                     
  while( len && tab->format[len] !='|')  len--;  
  if(len==0) return 1;                                    
  tab->format[len+1]=0;                                                        
                                                                          
   zeroline.next=NULL;                                                         
   lastln= &zeroline;                                                          
                                                                          
   newline=(linelist)m_alloc(sizeof(linerec)-STRSIZ+len+2);                    
   while (fgets1(newline->line ,len+1,txt) && newline->line[0]!='=')           
   {                                                                           
       newline->line[len+1]=0;                                                 
       for (i=strlen(newline->line);i<=len;i++) newline->line[i]=' ';          
       lastln->next=newline;                                                   
       newline->next=NULL;                                                     
       newline->pred=lastln;                                                   
       lastln=newline;                                                         
       newline=(linelist)m_alloc(sizeof(linerec)-STRSIZ+len+2);                
   }                                                                           
   free( newline);                                                             
   tab->strings=zeroline.next;                                                 
   if (tab->strings != NULL)tab->strings->pred=NULL;                           
   return 0;
}
Exemplo n.º 3
0
static void *  rd_rat(char* s)
{ 
  rmptr       m;
  NUM_TYPE    li;

   if (isdigit(s[0]))
   {
      sscanf(s,"%"STR_NUM,&li);

      m = (rmptr) m_alloc(sizeof(struct r_monom));
      m->n.c = li;
      m->d.c = NUM_ONE;
      m->n.v = NULL;
      m->d.v = NULL;
   }
   else
   {
      if (strlen(s) > 6)
         rderrcode = toolongidentifier;
      else
      {
         m = (rmptr) m_alloc(sizeof(struct r_monom));
         m->n.c = 1;
         m->d.c = 1;
         m->d.v = NULL;
         m->n.v = (vmptr) m_alloc(sizeof(struct vmrec));
         strcpy(m->n.v->name,s);
         m->n.v->next = NULL;
         m->n.v->deg = 1;
      }
   }
   return (void *) m;
}
Exemplo n.º 4
0
/** Method: avtGGCMFileFormat::GetVectorVar
 * Gets a vector variable associated with this file.  Although VTK has
 * support for many different types, the best bet is vtkFloatArray, since
 * that is supported everywhere through VisIt.
 * @param timestate The index of the timestate.  If GetNTimesteps returned
 *                  'N' time steps, this is guaranteed to be between 0 and N-1.
 * @param varname   The name of the variable requested.
 * Programmer: tfogal -- generated by xml2avt
 * Creation:   Thu Jun 1 13:38:54 PST 2006 */
vtkDataArray *
avtGGCMFileFormat::GetVectorVar(int timestate, const char *varname)
{
    char *fields[4];
    VectorNames(varname, fields);

    fields[3] = NULL;
    debug4 << "avtGGCMFileFormat::GetVectorVar(" << timestate << ", {"
           << fields[0] << ", " << fields[1] << ", " << fields[2] << "})"
           << std::endl;


    MHDdata *data;
    data = ggcm_read_mhd(this->GetFilename(), (const char**)fields);

    float ***vector[3];
    vector[0] = ggcm_field_matrix(data, dim[0],dim[1],dim[2], fields[0]);
    vector[1] = ggcm_field_matrix(data, dim[0],dim[1],dim[2], fields[1]);
    vector[2] = ggcm_field_matrix(data, dim[0],dim[1],dim[2], fields[2]);

    ggcm_free_data(data);

    float ***vec_gse[3];
    /* X */
    vec_gse[0] = (float***) m_alloc(dim[0], dim[1], dim[2]);
    ggcm_mhd_gse(vector[0], vec_gse[0], dim[0],dim[1],dim[2], fields[0]);
    m_free(vector[0]);
    /* Y */
    vec_gse[1] = (float***) m_alloc(dim[0], dim[1], dim[2]);
    ggcm_mhd_gse(vector[1], vec_gse[1], dim[0],dim[1],dim[2], fields[1]);
    m_free(vector[1]);
    /* Z */
    vec_gse[2] = (float***) m_alloc(dim[0], dim[1], dim[2]);
    ggcm_mhd_gse(vector[2], vec_gse[2], dim[0],dim[1],dim[2], fields[2]);
    m_free(vector[2]);

    free(fields[0]);
    free(fields[1]);
    free(fields[2]);

    unsigned int i,j,k, idx=0;
    vtkFloatArray *var = vtkFloatArray::New();
    var->SetName(varname); /* will VisIt do this for me?  can't hurt... */

    var->SetNumberOfComponents(3);
    var->SetNumberOfTuples(this->dim[0] * this->dim[1] * this->dim[2]);

    float v[3];
    for(k=0; k < dim[2]; ++k) {
        for(j=0; j < dim[1]; ++j) {
            for(i=0; i < dim[0]; ++i) {
                v[0] = vec_gse[0][i][j][k];
                v[1] = vec_gse[1][i][j][k];
                v[2] = vec_gse[2][i][j][k];
                var->InsertTuple(idx++, v);
            }
        }
    }
    return var;
}
Exemplo n.º 5
0
int BBMessageBox(int flg, const char *fmt, ...)
{
    const char *caption = BBAPPNAME;
    const char *message;
    char *p, *q;
    int r;
    va_list args;
    static int (WINAPI *pMessageBoxIndirectW)(CONST MSGBOXPARAMSW*);

    va_start(args, fmt);
    message = p = m_formatv(fmt, args);
    if ('#' == p[0] &&  NULL != (q = strchr(p+1, p[0])))
        // "#Title#Message" is wanted
        *q = 0, caption = p+1, message = q+1;

#ifdef BBTINY
    r = MessageBox (NULL, message, caption, flg | MB_SYSTEMMODAL);
#else

    MessageBeep(0);
    if (usingNT
     && load_imp(&pMessageBoxIndirectW, "user32.dll", "MessageBoxIndirectW")) {
        MSGBOXPARAMSW mp;
        int lc = 1+strlen(caption);
        int lm = 1+strlen(message);
        WCHAR *wcaption = (WCHAR*)m_alloc(lc * sizeof (WCHAR));
        WCHAR *wmessage = (WCHAR*)m_alloc(lm * sizeof (WCHAR));
        bbMB2WC(caption, wcaption, lc);
        bbMB2WC(message, wmessage, lm);

        memset(&mp, 0, sizeof mp);
        mp.cbSize = sizeof mp;
        mp.hInstance = hMainInstance;
        //mp.hwndOwner = NULL;
        mp.lpszText = wmessage;
        mp.lpszCaption = wcaption;
        mp.dwStyle = flg | MB_USERICON | MB_SYSTEMMODAL;
        mp.lpszIcon = MAKEINTRESOURCEW(IDI_BLACKBOX);
        r = pMessageBoxIndirectW(&mp);
        m_free(wcaption);
        m_free(wmessage);

    } else {
        MSGBOXPARAMSA mp;
        memset(&mp, 0, sizeof mp);
        mp.cbSize = sizeof mp;
        mp.hInstance = hMainInstance;
        //mp.hwndOwner = NULL;
        mp.lpszText = message;
        mp.lpszCaption = caption;
        mp.dwStyle = flg | MB_USERICON | MB_SYSTEMMODAL;
        mp.lpszIcon = MAKEINTRESOURCE(IDI_BLACKBOX);
        r = MessageBoxIndirectA(&mp);
    }
#endif

    m_free(p);
    return r;
}
Exemplo n.º 6
0
static HBITMAP read_bitmap(const char* path, bool delete_after)
{
    HWND hwnd_desk = GetDesktopWindow();
    HDC hdc_desk = GetDC(hwnd_desk);
    BITMAP bm;
#if 0
    HBITMAP bmp = (HBITMAP)LoadImage(NULL, path, IMAGE_BITMAP, 0,0, LR_LOADFROMFILE);
#else
    HBITMAP bmp = NULL;
    FILE *fp=fopen(path, "rb");
    if (fp)
    {
        BITMAPFILEHEADER hdr;
        fread(&hdr, 1, sizeof(hdr), fp);
        if (0x4D42 == hdr.bfType)
        {
            BITMAPINFOHEADER bih, *pbih; int CU, s; void *lpBits;
            fread(&bih, 1, sizeof(bih), fp);
            CU = bih.biClrUsed * sizeof(RGBQUAD);
            pbih = (PBITMAPINFOHEADER)m_alloc(bih.biSize + CU);
            memmove(pbih, &bih, bih.biSize);
            fread(&((BITMAPINFO*)pbih)->bmiColors, 1, CU, fp);
            s = hdr.bfSize - hdr.bfOffBits;
            lpBits = m_alloc(s);
            fseek(fp, hdr.bfOffBits, SEEK_SET);
            fread(lpBits, 1, s, fp);
            bmp = CreateDIBitmap(hdc_desk, pbih, CBM_INIT, lpBits, (LPBITMAPINFO)pbih, DIB_RGB_COLORS);
            m_free(lpBits);
            m_free(pbih);
        }
        fclose(fp);
    }
#endif
    if (bmp && GetObject(bmp, sizeof bm, &bm))
    {
        // convert in any case (20ms), bc if it's compatible, it's faster to paint.
        HDC hdc_old = CreateCompatibleDC(hdc_desk);
        HGDIOBJ old_bmp = SelectObject(hdc_old, bmp);
        HDC hdc_new = CreateCompatibleDC(hdc_desk);
        HBITMAP bmp_new = CreateCompatibleBitmap(hdc_desk, VScreenWidth, VScreenHeight);
        SelectObject(hdc_new, bmp_new);
        StretchBlt(hdc_new, 0, 0, VScreenWidth, VScreenHeight, hdc_old, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
        DeleteDC(hdc_new);
        DeleteObject(SelectObject(hdc_old, old_bmp));
        DeleteDC(hdc_old);
        bmp = bmp_new;
    }

    ReleaseDC(hwnd_desk, hdc_desk);
    if (delete_after)
        DeleteFile(path);
    return bmp;
}
Exemplo n.º 7
0
static void init(void) {
  if(!initialized) {initialized=1;
    rnl_init(); rnv_init();
    rnv_verror_handler=&silent_verror_handler;
    string=(char*)m_alloc(len_v=LEN_S*S_AVG_SIZE,sizeof(char));
    t2s=(int(*)[2])m_alloc(len_2=LEN_2,sizeof(int[2]));
    rules=(int(*)[3])m_alloc(len_r=LEN_R,sizeof(int[3]));
    ht_init(&ht_s,LEN_S,&hash_s,&equal_s);
    value=(char*)m_alloc(len_v=LEN_V,sizeof(char));
    text=(char*)m_alloc(len_txt=LEN_T,sizeof(char));
    windup();
  }
}
Exemplo n.º 8
0
void rx_init(void) {
  if(!initialized) { initialized=1;
    pattern=(int *)m_alloc(len_p=P_AVG_SIZE*LEN_P,sizeof(int));
    r2p=(int (*)[2])m_alloc(len_2=LEN_2,sizeof(int[2]));
    regex=(char*)m_alloc(len_r=R_AVG_SIZE*LEN_R,sizeof(char));
    memo=(int (*)[M_SIZE])m_alloc(len_m=LEN_M,sizeof(int[M_SIZE]));

    ht_init(&ht_p,LEN_P,&hash_p,&equal_p);
    ht_init(&ht_2,LEN_2,&hash_2,&equal_2);
    ht_init(&ht_r,LEN_R,&hash_r,&equal_r);
    ht_init(&ht_m,LEN_M,&hash_m,&equal_m);

    windup();
  }
}
Exemplo n.º 9
0
static void *  uact0(char* ch,void* mm)
{char  *m, *ans;

   m = (char *) mm;
   ans=(char *) m_alloc(strlen(m)+10);

   if (strcmp(ch,"-") == 0)
   {  if (m[0] == 'M')
     {
        if (m[2] == '-') sprintf(ans,"M|%s",m+3);
        else  sprintf(ans,"M|-%s",m+2);
     }  else  sprintf(ans,"M|-(%s)",m+2);
   }
   
   if (strcmp(ch,"G") == 0)
   {  if(forR_code)
      {
        if (r_reading0) sprintf(ans,"M|-G(ln,%s)",m+2);
        else            sprintf(ans,"M|G(ln,%s)",m+2);
      }else
      {
        if (r_reading0) sprintf(ans,"M|-G(%s)",m+2);
        else            sprintf(ans,"M|G(%s)",m+2);
      }      
   }   
   return (void*) ans;
}
Exemplo n.º 10
0
static void*  rd_rcode(char* s)
{  char    * p;
   int  num;

   p = (char *) m_alloc(4+VAR_NAME_SIZE);
   p[0]=0;
   if (strlen(s) == 2 && s[1] > '0' && s[1] <= '9')
   {
      switch (s[0])
      {
        case 'p':
        case 'P':
               num = s[1] - '0';
               num = momsubst[num-1];
               if (num > 0) sprintf(p,"M|p%d",num);
                    else    sprintf(p,"M|-p%d",-num);
            break;

        case 'm':
               num = s[1] - '0';
               num = indsubst[num-1];
	       sprintf(p,"M|m%d",num);
               break;           
        case 'M':
               num = s[1] - '0';
               num = indsubst[num-1]-1;
	       sprintf(p,"M|m%d",num);
      } 
      if (strcmp(s,"G5") == 0) 
      { if(forR_code) strcpy(p,"M|G(ln,A)"); else strcpy(p,"M|G5");}
   }
   if (!strlen(p)) sprintf(p,"M|%s",s);
   return (void*) p;
}
Exemplo n.º 11
0
static void  insertcopy(hlpcsptr c)
{  hlpcsptr cc; 
 
   cc = (hlpcsptr) m_alloc(sizeof(struct hlpcsrec));
   *cc = *c; 
   c->next = cc; 
} 
Exemplo n.º 12
0
static void  mkorientedloops(hlpcsptr* alll)
{int        i, j; 
 hlpcsptr    tmp; 

   tmp = *alll; 
   while (tmp != NULL) 
   { 
      tmp->sgn = 1; 
      tmp = tmp->next; 
   } 
   tmp = *alll; 
   while (tmp != NULL) 
   { 
      i = 1; j = 1; 
      while (find1(&i,&j,tmp)) insertorient(i,j,tmp); 
      tmp = tmp->next; 
   } 
   tmp = *alll; 
   while (tmp != NULL) 
   { 
      for (i = 0; i < vcs_stat.sizet; i++) 
      for (j = 0; j < vcs_stat.valence[i]; j++) 
      if (tmp->hlpcs[i][j] != 0) tmp->hlpcs[i][j] --  ;               
      tmp = tmp->next; 
   } 

   tmp = (hlpcsptr) m_alloc(sizeof(struct hlpcsrec)); 
   /*    addition  of origin graph  */ 
   for (i = 1; i <= vcs_stat.sizet; i++) 
      for (j = 1; j <= vcs_stat.valence[i-1]; j++) tmp->hlpcs[i-1][j-1] = 0; 
   tmp->sgn = 1; 
   tmp->next = *alll; 
   *alll = tmp;
          
}   /*  MkOrientedLoops  */ 
Exemplo n.º 13
0
static int
gather_faked( void (*add)(const void*, size_t, int), int requester,
	      size_t length, int level )
{
    static int initialized=0;
    size_t n;
    char *buffer, *p;

    if( !initialized ) {
	log_info(_("WARNING: using insecure random number generator!!\n"));
	tty_printf(_("The random number generator is only a kludge to let\n"
		   "it run - it is in no way a strong RNG!\n\n"
		   "DON'T USE ANY DATA GENERATED BY THIS PROGRAM!!\n\n"));
	initialized=1;
      #ifdef HAVE_RAND
	srand(make_timestamp()*getpid());
      #else
	srandom(make_timestamp()*getpid());
      #endif
    }

    p = buffer = m_alloc( length );
    n = length;
  #ifdef HAVE_RAND
    while( n-- )
	*p++ = ((unsigned)(1 + (int) (256.0*rand()/(RAND_MAX+1.0)))-1);
  #else
    while( n-- )
	*p++ = ((unsigned)(1 + (int) (256.0*random()/(RAND_MAX+1.0)))-1);
  #endif
    add_randomness( buffer, length, requester );
    m_free(buffer);
    return 0; /* okay */
}
Exemplo n.º 14
0
static int class_info_register(const char *class_name, HINSTANCE hInstance)
{
    struct class_info *p = *find_class(class_name);
    if (NULL == p)
    {
        WNDCLASS wc;
        ZeroMemory(&wc,sizeof(wc));

        wc.lpfnWndProc  = BBP_WndProc;  // our window procedure
        wc.hInstance    = hInstance;    // hInstance of .dll
        wc.lpszClassName = class_name;  // our window class name
        wc.style = CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW;// | CS_DROPSHADOW;
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc.cbWndExtra = sizeof (void*);

        if (FALSE == RegisterClass(&wc))
        {
            //dbg_printf("failed to register %s", wc.lpszClassName);
            return 0;
        }

        p = (struct class_info*)m_alloc(sizeof(struct class_info));
        p->next = CI;
        CI = p;
        p->refc = 0;
        strcpy(p->name, class_name);
        p->hInstance = hInstance;
        //dbg_printf("registered class <%s> %x", wc.lpszClassName, wc.hInstance);
    }

    p->refc ++;
    return 1;
}
Exemplo n.º 15
0
/* method==0 to replace current $PATH, and 1 to append to current
   $PATH.  */
int set_exec_path(const char *path,int method)
{
  char *p,*curpath=NULL;
  size_t curlen=0;

  if(method==1 && (curpath=getenv("PATH")))
    curlen=strlen(curpath)+1;

  p=m_alloc(5+curlen+strlen(path)+1);
  strcpy(p,"PATH=");

  if(curpath)
    {
      strcat(p,curpath);
      strcat(p,":");
    }

  strcat(p,path);

  /* Notice that path is never freed.  That is intentional due to the
     way putenv() works.  This leaks a few bytes if we call
     set_exec_path multiple times. */

  if(putenv(p)!=0)
    return G10ERR_GENERAL;
  else
    return 0;
}
Exemplo n.º 16
0
static void
init_compress( compress_filter_context_t *zfx, z_stream *zs )
{
    int rc;
    int level;

    if( opt.compress >= 0 && opt.compress <= 9 )
	level = opt.compress;
    else if( opt.compress == -1 )
	level = Z_DEFAULT_COMPRESSION;
    else if( opt.compress == 10 ) /* remove this ! */
	level = 0;
    else {
	log_error("invalid compression level; using default level\n");
	level = Z_DEFAULT_COMPRESSION;
    }


    if( (rc = zfx->algo == 1? deflateInit2( zs, level, Z_DEFLATED,
					    -13, 8, Z_DEFAULT_STRATEGY)
			    : deflateInit( zs, level )
			    ) != Z_OK ) {
	log_fatal("zlib problem: %s\n", zs->msg? zs->msg :
			       rc == Z_MEM_ERROR ? "out of core" :
			       rc == Z_VERSION_ERROR ? "invalid lib version" :
						       "unknown error" );
    }

    zfx->outbufsize = 8192;
    zfx->outbuf = m_alloc( zfx->outbufsize );
}
Exemplo n.º 17
0
/****************
 * Return a pointer to a randomized buffer of level 0 and LENGTH bits
 * caller must free the buffer.
 * Note: The returned value is rounded up to bytes.
 */
byte *
get_random_bits( size_t nbits, int level, int secure )
{
    byte *buf, *p;
    size_t nbytes = (nbits+7)/8;

    if( quick_test && level > 1 )
	level = 1;
    MASK_LEVEL(level);
    if( level == 1 ) {
	rndstats.getbytes1 += nbytes;
	rndstats.ngetbytes1++;
    }
    else if( level >= 2 ) {
	rndstats.getbytes2 += nbytes;
	rndstats.ngetbytes2++;
    }

    buf = secure && secure_alloc ? m_alloc_secure( nbytes ) : m_alloc( nbytes );
    for( p = buf; nbytes > 0; ) {
	size_t n = nbytes > POOLSIZE? POOLSIZE : nbytes;
	read_pool( p, n, level );
	nbytes -= n;
	p += n;
    }
    return buf;
}
Exemplo n.º 18
0
static void  mkallloops(hlpcsptr indpl, hlpcsptr* alll)
{hlpcsptr   alll_, tmpl; 
 int       i, j; 

   if (indpl == NULL) 
      *alll = NULL; 
   else 
   { 
      mkallloops(indpl->next,&alll_); 
      *alll = indpl; 
      (*alll)->next = alll_; 
      while (alll_ != NULL) 
      { 
         tmpl = (hlpcsptr) m_alloc(sizeof(struct hlpcsrec));
         tmpl->next = *alll; 
         *alll = tmpl; 
         for (i = 1; i <= vcs_stat.sizet; i++) 
            for (j = 1; j <= vcs_stat.valence[i-1]; j++) 
               (*alll)->hlpcs[i-1][j-1] = 
                  (indpl->hlpcs[i-1][j-1] + alll_->hlpcs[i-1][j-1]) % 2; 
         alll_ = alll_->next; 
      } 
   }   
    
} 
Exemplo n.º 19
0
/****************
 * Convert string, which is in native encoding to UTF8 and return the
 * new allocated UTF8 string.
 */
char *
native_to_utf8( const char *string )
{
    const byte *s;
    char *buffer;
    byte *p;
    size_t length=0;

    if (no_translation) {
        buffer = m_strdup (string);
    }
    else if( active_charset ) {
	for(s=string; *s; s++ ) {
	    length++;
	    if( *s & 0x80 )
		length += 2; /* we may need 3 bytes */
	}
	buffer = m_alloc( length + 1 );
	for(p=buffer, s=string; *s; s++ ) {
	    if( *s & 0x80 ) {
		ushort val = active_charset[ *s & 0x7f ];
		if( val < 0x0800 ) {
		    *p++ = 0xc0 | ( (val >> 6) & 0x1f );
		    *p++ = 0x80 | (  val & 0x3f );
		}
		else {
		    *p++ = 0xe0 | ( (val >> 12) & 0x0f );
		    *p++ = 0x80 | ( (val >>  6) & 0x3f );
		    *p++ = 0x80 | (  val & 0x3f );
		}
	    }
Exemplo n.º 20
0
int dsl_allows(char *typ,char *ps,char *s,int n) {
  char *buf,*sp,*bp, *p;
  int np,lenp;
  SCM ret=BOOL_F;

  if(dsl_scm) {
    p=ps; np=0;
    while(*p) {++np; while(*(p++)); while(*(p++));}
    lenp=p-ps-2*np;
    buf=(char*)m_alloc(
      strlen(ALLOWS)+np*strlen(PARAM)+2*(strlen(typ)+lenp+n)+1,
      sizeof(char));
    bp=buf; sp=ALLOWS;
    shere(bp,sp); bp+=stresc(bp,typ);
    shere(bp,sp); /* parameters */
    p=ps;
    while(np--) {
      char *sp=PARAM;
      shere(bp,sp); bp+=stresc(bp,p); while(*(p++));
      shere(bp,sp); bp+=stresc(bp,p); while(*(p++));
      while(*sp) *(bp++)=*(sp++);
    }
    shere(bp,sp); bp+=strnesc(bp,s,n);
    while((*(bp++)=*(sp++)));
    ret=scm_evstr(buf);
    m_free(buf);
  }
  return ret!=BOOL_F;
}
Exemplo n.º 21
0
int
parse_via_header (struct sip_msg *msg, char ip[])
{
  size_t len;
  char *via = NULL;
  char *addr = NULL;
  char *tmp = NULL;
  char *tmp1 = NULL;
  int i;

  if (!msg->via1)
    return 1;

  /* locate via and its length first */
  via = msg->orig + (msg->via1 - msg->buf);
  len = find_end (via, msg->orig + msg->len);

  addr = m_alloc (len + 1);
  memcpy (addr, via, len);
  addr[len] = '\0';

  tmp = strstr (addr, "SIP/2.0");
  if (tmp)
    {
      len -= (tmp - addr);
      if ((tmp1 = strstr (tmp, "UDP")) || (tmp1 = strstr (tmp, "TCP")))
        {
          tmp1 += 3;
          len -= 3;
        }
      else
        {
          m_free (addr);
          return 1;             // No UDP or TCP
        }
      while ((*tmp1 == ' ') && (len > 0))
        {
          tmp1++;               // remove space
          len--;
        }

      tmp = tmp1;
      while ((isdigit (*tmp1) || (*tmp1 == '.')) && (len > 0)
             && (tmp1 - tmp < 15))
        {
          /* Just copy the bytes now,
           * we will check if it is right or not with inet_aton later on 
           */
          ip[tmp1 - tmp] = *tmp1;
          tmp1++;
          len--;
        }
      ip[tmp1 - tmp + 1] = '\0';
      m_free (addr);
      return 0;
    }
  else
    return 1;                   // no SIP/2.0    
}
Exemplo n.º 22
0
void rnc_init(void) {
  if(!initialized) { initialized=1;
    rn_init();
    len_p=LEN_P; path=(char*)m_alloc(len_p,sizeof(char));
    /* initialize scopes */
    sc_init(&nss); sc_init(&dts); sc_init(&defs); sc_init(&refs); sc_init(&prefs);
  }
}
Exemplo n.º 23
0
int rnc_bind(struct rnc_source *sp,char *fn,int fd) {
  rnc_source_init(sp,fn);
  if((sp->fd=fd)!=-1) {
    sp->buf=(char*)m_alloc(BUFSIZE,sizeof(char)); sp->flags=SRC_FREE;
    sp->n=sp->i=0; sp->complete=0; rnc_read(sp); sp->i=u_bom(sp->buf,sp->n);
  }
  return sp->fd;
}
Exemplo n.º 24
0
LPITEMIDLIST duplicateIDlist(LPCITEMIDLIST pidl)
{
	LPITEMIDLIST pidlNew; int cb;
	if (NULL==pidl) return NULL;
	pidlNew = (LPITEMIDLIST)m_alloc(cb = GetIDListSize(pidl));
	memcpy(pidlNew, pidl, cb);
	return pidlNew;
}
Exemplo n.º 25
0
Arquivo: ht.c Projeto: btolfa/rnv
void ht_init(struct hashtable *ht,int len,int (*hash)(int),int (*equal)(int,int)) {
  assert(len>0);
  ht->tablen=1; len*=LOAD_FACTOR;
  while(ht->tablen<len) ht->tablen<<=1;
  ht->limit=ht->tablen/LOAD_FACTOR;
  ht->table=(int*)m_alloc(ht->tablen<<1,sizeof(int)); /* the second half is hash values */
  ht->hash=hash; ht->equal=equal;
  ht_clear(ht);
}
Exemplo n.º 26
0
plugin_info *BBP_create_info(void)
{
    plugin_info *PI;
    PI = (plugin_info *)m_alloc(sizeof (plugin_info));
    memset(PI, 0, sizeof(plugin_info));
    PI->pos_changed = pos_changed;
    PI->process_broam = process_broam;
    return PI;
}
Exemplo n.º 27
0
static void*  smpl_emit(varptr ex)
{longstrptr   ans;
 char     s[STRSIZ];
 int      k, bt, nv, deg;
 int      star;
 varptr       ex_, exbeg;

   if (ex == NULL) return NULL;

   if (ex->sgn == '-')
   {
      ex_ = ex;

      while (ex_->next != NULL && ex_->next->sgn == '-')
      ex_ = ex_->next;

      if (ex_->next != NULL)
      {
         exbeg = ex_->next;
         ex_->next = exbeg->next;
         exbeg->next = ex;
         ex = exbeg;
      }
      
   }

   ans = (longstrptr)m_alloc(sizeof(longstr));
   ans->len = 0; 
   while (ex != NULL) 
   { 
      sprintf(s,"%c",ex->sgn);       
      star = (strcmp((ex->coef)->name,"1") != 0); 
      if (star || ex->vars[0] == 0) strcat(s,(ex->coef)->name); 
      if (ex->vars[0] != 0) 
      { 
         bt = (ex->vars[0]); 
         deg = 1; 
         for (k = 1; ex->vars[k]; k++) 
         { 
            nv = (ex->vars[k]); 
            if (bt != nv) 
            {
               if (star) strcat(s,"*"); else star = 1;     
               strcat(s,writevardeg(bt,deg)); 
               deg = 1; 
               bt = nv; 
            } 
            else ++(deg); 
         } 
         if (star) strcat(s,"*");  else  star = 1;      
         strcat(s,writevardeg(bt,deg)); 
      } 
      addstring(ans,s); 
      ex = ex->next; 
   } 
   return (void*) ans; 
}
Exemplo n.º 28
0
static void init(void) {
  if(!initialized) {initialized=1;
    rnl_init();
    rnv_init(); rnv_verror_handler=&verror_handler_rnv;
    drv_add_dtl(DXL_URL,&dxl_equal,&dxl_allows);
    drv_add_dtl(DSL_URL,&dsl_equal,&dsl_allows);
    quebuf=(char*)m_alloc(len_q=LEN_B,sizeof(char));
  }
}
Exemplo n.º 29
0
char *rnx_p2str(int p) {
  char *s=NULL,*s1;
  int dt,ps,val,nc,p1;
  switch(RN_P_TYP(p)) {
  case RN_P_ERROR: s=s_clone("error"); break;
  case RN_P_NOT_ALLOWED: s=s_clone("notAllowed"); break;
  case RN_P_EMPTY: s=s_clone("empty"); break;
  case RN_P_TEXT: s=s_clone("text"); break;
  case RN_P_CHOICE: s=s_clone("choice (|)"); break;
  case RN_P_INTERLEAVE: s=s_clone("interleave (&)"); break;
  case RN_P_GROUP: s=s_clone("group (,)"); break;
  case RN_P_ONE_OR_MORE: s=s_clone("one or more (+)"); break;
  case RN_P_LIST: s=s_clone("list"); break;
  case RN_P_DATA: rn_Data(p,dt,ps);
    s1=rnx_nc2str(dt);
    s=(char*)m_alloc(strlen("data ")+1+strlen(s1),sizeof(char));
    strcpy(s,"data "); strcat(s,s1);
    m_free(s1);
    break;
  case RN_P_DATA_EXCEPT: s=s_clone("dataExcept (-)");  break;
  case RN_P_VALUE: rn_Value(p,dt,val);
    s1=rnx_nc2str(dt);
    s=(char*)m_alloc(strlen("value \"\" ")+1+strlen(s1)+strlen(rn_string+val),sizeof(char));
    strcpy(s,"value "); strcat(s,s1); strcat(s," \""); strcat(s,rn_string+val); strcat(s,"\"");
    m_free(s1);
    break;
  case RN_P_ATTRIBUTE: rn_Attribute(p,nc,p1);
    s1=rnx_nc2str(nc);
    s=(char*)m_alloc(strlen("attribute ")+1+strlen(s1),sizeof(char));
    strcpy(s,"attribute "); strcat(s,s1);
    m_free(s1);
    break;
  case RN_P_ELEMENT: rn_Element(p,nc,p1);
    s1=rnx_nc2str(nc);
    s=(char*)m_alloc(strlen("element ")+1+strlen(s1),sizeof(char));
    strcpy(s,"element "); strcat(s,s1);
    m_free(s1);
    break;
  case RN_P_REF: s=s_clone("ref"); break;
  case RN_P_AFTER: s=s_clone("after"); break;
  default: assert(0);
  }
  return s;
}
Exemplo n.º 30
0
void matlib_main()
{
    MATRIX *A, *B, *C;
    MATRIX *At, *Bt;
    long n, ni, i;
    double sum;

    random_1(-1);

    n = query_long("dimension of arrays", 3L);
    ni = query_long("number of iterations", 100L);

#ifdef VAX_VMS
    init_stats();
#endif

    m_alloc(&A, n, n);
    m_alloc(&At, n, n);
    m_alloc(&B, n, n);
    m_alloc(&Bt, n, n);
    m_alloc(&C, n, n);
    for (i=sum=0; i<ni; i++) {

        m_rand(At, -1.0L, 1.0L);
        m_trans(A, At);

        m_invert(B, A);
        m_mult(C, A, B);

        sum += fabs(m_det(C)-1.0);

    }
    m_free(&A);
    m_free(&At);
    m_free(&B);
    m_free(&Bt);
    m_free(&C);

    printf("M.A.D.{DET{A.INV(A))}-1} = %e\n", sum/ni);

#ifdef VAX_VMS
    report_stats(stdout, "stats: ");
#endif
}