Beispiel #1
0
void  CXMLObject::SetData ( cpstr Data )  {
pstr p,d;
int  n;
  // count ampersands
  p = pstr(Data);
  n = 0;
  while (*p)  {
    if (*p=='&')  n += 4;
    p++;
  }
  // calculate the Data length
  n += strlen(Data) + 1;  // eugene
  // allocate data space
  if (objData)  delete[] objData;
  objData = new char[n];
  // copy data, preceeding ampersands with the escape
  p = pstr(Data);
  d = objData;
  while (*p)  {
    if (*p=='&')  {
      d[0] = '&';
      d[1] = 'a';
      d[2] = 'm';
      d[3] = 'p';
      d[4] = ';';
      d += 5;
    } else  {
      *d = *p;
      d++;
    }
    p++;
  }
  *d = char(0);
}
Beispiel #2
0
static int pnum(char *str, int num, int fwidth, int maxsize, int mode, int *cursize)
{
    char buf[11],*p = &buf[9], *nm;
    int i;
    TIME_DATA *td = __locale_data[LC_TIME];
    nm = td->ths;
    buf[0] = 0;
    if (mode == 'O') {
        for (i=0; i < num; i++) {
            if (*nm == 0)
                break ;
            nm += strlen(nm);
        }
        if (*nm)
            return(pstr(str,nm,maxsize,mode,cursize));
    }
    for (i=0; i < 10; i++)
        buf[i] = '0';
    buf[10] = 0;
    while (num) {
        *p-- = (char)(num %10)+'0';
        num = num / 10;
    }
    return(pstr(str,buf+10-fwidth,maxsize,mode,cursize));
}
Beispiel #3
0
void sdError_P(const char* str) {
  cout << pstr("error: ");
  cout << pgm(str) << endl;
  if (card.errorCode()) {
    cout << pstr("SD error: ") << hex << int(card.errorCode());
    cout << ',' << int(card.errorData()) << dec << endl;
  }
  while (1);
}
Beispiel #4
0
/*
 * Test Userland Thread Scheduler (UTS) suite for KSE.
 */
int
main(void)
{
	int i;

	runq_init(&runq1);
	init_uts(&data1, &runq1);
	init_uts(&data2, &runq1);
	thread_start(&data1, aaaa, '+');
	thread_start(&data1, aaaa, '-');
	start_uts(&data1, 0);
	start_uts(&data2, 0);

//	start second ksegrp
	runq_init(&runq2);
	init_uts(&data3, &runq2);
	init_uts(&data4, &runq2);
	thread_start(&data3, newkse, 0);
	thread_start(&data3, aaaa, '*');
	thread_start(&data3, aaaa, '.');
	start_uts(&data3, 1);

	for (i = 0;1;i++) {
//		if (i < 1000)
//			thread_start(aaaa, 'a' + (i % 26));
		pchar('A' + (i % 26));
		nano(5);
	}
	pstr("\n** main() exiting **\n");
	return (EX_OK);
}
Beispiel #5
0
int CXMLObject::AddMMCIFLoop ( PCMMCIFLoop mmCIFLoop )  {
PCXMLObject XMLObject1,XMLObject2,XMLObject3;
pstr        SName,Tag,Field,ccifTag;
int         nTags,nRows,i,j,k;

  XMLObject1 = this;

  ccifTag = NULL;

  SName = mmCIFLoop->GetCategoryName();
  if (SName)  {
    if (SName[0]!=char(1))
      XMLObject1 = new CXMLObject ( getCCIFTag(ccifTag,SName) );
  }

  k = 0;
  nTags = mmCIFLoop->GetNofTags   ();
  nRows = mmCIFLoop->GetLoopLength();
  for (i=0;i<nRows;i++)  {
    XMLObject2 = new CXMLObject ( pstr("row"),
                      new CXMLObject(pstr("_sernum_"),i+1) );
    for (j=0;j<nTags;j++)  {
      Tag = mmCIFLoop->GetTag ( j );
      if (Tag)  {
        XMLObject3 = new CXMLObject ( getCCIFTag(ccifTag,Tag) );
        Field = mmCIFLoop->GetField ( i,j );
        if (Field)  {
          if (Field[0]!=char(2))  XMLObject3->SetData ( Field );
                            else  XMLObject3->SetData ( &(Field[1]) );
        }
        XMLObject2->AddObject ( XMLObject3 );
        k++;
      }
    }
    XMLObject1->AddObject ( XMLObject2 );
  }
  
  if (SName)  {
    if (SName[0]!=char(1))
      AddObject ( XMLObject1 );
  }

  if (ccifTag)  delete[] ccifTag;

  return k;

}
Beispiel #6
0
void defile(vector<string> &options)
{ bool changed;
  do {
    changed=false;
    vector<string> reoptions=options;
    options.clear();
    ITERATE(vector<string>, oi, reoptions) {
      if ((*oi)[0]=='@') {
        string::iterator be((*oi).end());
        do --be; while ((*be!=':') && (*be!='@'));
        if (*be=='@') {
          ifstream pstr(string(be+1, (*oi).end()).c_str());
          if (!pstr.is_open() || pstr.fail() || pstr.eof())
            raiseError("invalid parameter file");
          while (!pstr.fail() && !pstr.eof()) {
            string nl=getSLine(pstr);
            if (nl.length()) options.push_back(string(nl.begin(), nl.end()));
          }
        }
        else {
          string filename((*oi).begin()+1, be), lineNos(be+1, (*oi).end());
          int lineNo=atoi(lineNos.c_str());
          if (!lineNo)
            raiseError("Invalid line number (%s) for parameter file %s.", lineNos.c_str(), filename.c_str());
          ifstream pstr(filename.c_str());
          if (!pstr.is_open() || pstr.fail() || pstr.eof())
            raiseError("Invalid parameter file (%s).", (*oi).c_str());
          while(--lineNo) {
            getSLine(pstr);
            if (pstr.fail() || pstr.eof())
              raiseError("can't read parameter file %s to line %s", filename.c_str(), lineNos.c_str());
          }
          string nl=getSLine(pstr);
          if (nl[0]=='=') options.push_back(string(nl.begin()+1, nl.end()));
          else {
            vector<string> ns;
            string2atoms(nl, ns);
            ITERATE(vector<string>, ni, ns) options.push_back(*ni);
          }
        }
        changed=true;
      }
      else options.push_back(*oi);
    }
  } while (changed);
}
Beispiel #7
0
void  CXMLObject::SetTag ( cpstr Tag )  {
pstr p,t;
int  n;

  // count ampersands
  p = pstr(Tag);
  n = 0;
  while (*p)  {
    if (*p=='&')  n++;
    p++;
  }
  // calculate the tag length
  n = n*4 + strlen(Tag) + 1;
  // substract leading underscores
  p = pstr(Tag);
  while (*p=='_')  {
    p++;
    n--;
  }
  // allocate tag space
  if (objTag)  delete[] objTag;
  objTag = new char[n];
  // copy tag, replacing square brackets and ampersands
  t = objTag;
  while (*p)  {
    if (*p=='[')  {
      *t = '-';
      t++;
    } else if (*p==']')  {
      if ((p[1]) && (p[1]!='['))  {
        *t = '-';
        t++;
      }
    } else if (*p=='&')  {
      strcpy ( t,"_and_" );
      if (p[1])  t += 5;
           else  t += 4;
    } else  {
      *t = *p;
      t++;
    }
    p++;
  }
  *t = char(0);
}
Beispiel #8
0
void
perr(Io *f)
{
	char err[ERRMAX];
	
	err[0] = 0;
	errstr(err, sizeof err);
	pstr(f, err);
	errstr(err, sizeof err);
}
Beispiel #9
0
int		main(int argc, char **argv)
{
	/*
	**	ft_atoi
	*/
	pstr("ft_atoi: ");
	if (ft_atoi_test() == 1)
		pstrnl("OK");
	else
		pstrnl("Fail");
}
Beispiel #10
0
void
pwrd(Io *f, char *s)
{
	char *t;
	for(t=s;*t;t++)
		if(!wordchr(*t))
			break;
	if(t==s || *t)
		pquo(f, s);
	else
		pstr(f, s);
}
Beispiel #11
0
int
main(void)
{
	runq_init(&runq1);
	init_uts(&data1, &runq1);
	thread_start(&data1, deadloop, 0);
	thread_start(&data1, deadloop, 0);
	thread_start(&data1, deadloop, 0);
	start_uts(&data1, 0);
	pause();
	pstr("\n** main() exiting **\n");
	return (EX_OK);
}
Beispiel #12
0
/*
 *	"case" label
 */
void docase (void )
{
	INTPTR_T	val;

	val = 0;
	if (readswitch ()) {
		if (!number (&val))
			if (!pstr (&val))
				error ("bad case label");
		addcase (val);
		if (!match (":"))
			error ("missing colon");
	} else
		error ("no active switch");
}
Beispiel #13
0
int tuv_run(uv_loop_t* loop, tuv_loop_cb loopcb, tuv_final_cb fincb,
            void* param) {

  loop->raw_loopcb = loopcb;
  loop->raw_finalcb = fincb;
  loop->raw_param = param;

  mbed::util::FunctionPointer1<void, void*> pstr(handle_loopfinal);
  minar::Scheduler::postCallback(pstr.bind(loop))
                      .tolerance(minar::milliseconds(1))
                      .delay(minar::milliseconds(1))
                      ;

  return 0;
}
Beispiel #14
0
/*
 * Initialise threading.
 */
static void
init_uts(struct uts_data *data, struct uts_runq *q)
{
	struct kse_thr_mailbox *tm;
	int mib[2];
	char	*p;
#if 0
	size_t len;
#endif

	/*
	 * Create initial thread.
	 */
	tm = (struct kse_thr_mailbox *)calloc(1, sizeof(struct kse_thr_mailbox));

	/* Throw us into its context. */
	getcontext(&tm->tm_context);

	/* Find our stack. */
	mib[0] = CTL_KERN;
	mib[1] = KERN_USRSTACK;
#if 0
	len = sizeof(p);
	if (sysctl(mib, 2, &p, &len, NULL, 0) == -1)
		pstr("sysctl(CTL_KER.KERN_USRSTACK) failed.\n");
#endif
	p = (char *)malloc(MAIN_STACK_SIZE) + MAIN_STACK_SIZE;
	pfmt("main() : 0x%x\n", tm);
	pfmt("eip -> 0x%x\n", tm->tm_context.uc_mcontext.mc_eip);
	tm->tm_context.uc_stack.ss_sp = p - MAIN_STACK_SIZE;
	tm->tm_context.uc_stack.ss_size = MAIN_STACK_SIZE;

	/*
	 * Create KSE mailbox.
	 */
	p = (char *)malloc(THREAD_STACK_SIZE);
	bzero(&data->mb, sizeof(struct kse_mailbox));
	data->mb.km_stack.ss_sp = p;
	data->mb.km_stack.ss_size = THREAD_STACK_SIZE;
	data->mb.km_func = (void *)uts;
	data->mb.km_udata = data;
	data->mb.km_quantum = 10000;
	data->cur_thread = tm;
	data->runq = q;
	pfmt("uts() at : 0x%x\n", uts);
	pfmt("uts stack at : 0x%x - 0x%x\n", p, p + THREAD_STACK_SIZE);
}
Beispiel #15
0
int constant(LVALUE *lval)
{
        constype=CINT;
        conssign=dosigned;
        lval->is_const = 1 ;            /* assume constant will be found */
        if ( fnumber(&lval->const_val) ) {
                lval->val_type=DOUBLE;
		if ( doublestrings ) {
		    immedlit(litlab);
		    outdec(lval->const_val); nl();
		    callrts("__atof2");
                    WriteDefined("math_atof",1);
		} else {
		    immedlit(dublab);
		    outdec(lval->const_val); nl();
		    callrts("dload");
		}
                lval->is_const = 0 ;                    /*  floating point not constant */
                lval->flags=0;
                return(1);
        }
        else if ( number(&lval->const_val) || pstr(&lval->const_val) ) {
/* Insert long stuff/long pointer here? */
		if ( (unsigned long )lval->const_val >= 65536LU )
			constype = LONG;

                lval->val_type = constype ;
                lval->flags = (lval->flags&MKSIGN)|conssign;
                if (constype == LONG) vlongconst(lval->const_val);
                else vconst(lval->const_val);
                return(1);
        }
        else if ( tstr(&lval->const_val) ) {
                lval->is_const = 0 ;                    /* string address not constant */
                lval->ptr_type=CCHAR;   /* djm 9/3/99 */
                lval->val_type=CINT;
                lval->flags=0;
                immedlit(litlab);
        }
        else {
                lval->is_const = 0 ;
                return(0);       
        }
        outdec(lval->const_val);
        nl();
        return(1);
}
Beispiel #16
0
int
main(int argc, char *argv[])
{
#define p(m, v, fmt)	printf(".ds %s " fmt "\n", m, v)
#define pstr(m)		p(#m, m, "%s")
#define pint(m)		p(#m, m, "%d")
	pstr(AUFS_VERSION);
	pstr(AUFS_XINO_FNAME);
	pstr(AUFS_XINO_DEFPATH);
	pint(AUFS_DIRWH_DEF);
	pstr(AUFS_WH_PFX);
	pstr(AUFS_WKQ_NAME);
	pint(AUFS_NWKQ_DEF);
	pstr(AUFS_WH_DIROPQ);
	pstr(AUFS_WH_BASENAME);
	pstr(AUFS_WH_PLINKDIR);
	pint(AUFS_BRANCH_MAX);
	return 0;
}
Beispiel #17
0
int
main(int argc, char *argv[])
{
#define p(m, v, fmt)	printf("%s=" fmt "\n", m, v)
#define pstr(m)		p(#m, m, "%s")
#define pint(m)		p(#m, m, "%d")
	pstr(AUFS_VERSION);
	pint(AUFS_SUPER_MAGIC);
	printf("AUFS_SUPER_MAGIC_HEX=0x%x\n", AUFS_SUPER_MAGIC);
	pstr(AUFS_WH_PFX);
	pstr(AUFS_WH_PFX2);
	pint(AUFS_MAX_NAMELEN);
	pstr(AUFS_WKQ_NAME);
	pstr(AUFS_WH_DIROPQ);
	pstr(AUFS_WH_BASE);
	pstr(AUFS_WH_PLINKDIR);
	pstr(AUFS_WH_ORPHDIR);
	//pint(AUFS_BRANCH_MAX);
	return 0;
}
Beispiel #18
0
PCXMLObject mmCIF2XML ( PCMMCIFData mmCIFData, int * rc )  {
PCXMLObject XMLObject;
pstr        dataName;
int         k;
  XMLObject = NULL;
  if (rc) *rc = -2;
  if (mmCIFData)  {
    dataName = mmCIFData->GetDataName();
    if (dataName)  {
      if (dataName[0])
        XMLObject = new CXMLObject ( dataName );
    }
    if (!XMLObject)
      XMLObject = new CXMLObject ( pstr("no_data_name") );
    k = XMLObject->AddMMCIFData ( mmCIFData );
    if (rc)  *rc = k;
  }
  return XMLObject;
}
Beispiel #19
0
//------------------------------------------------------------------------------
// initialize appropriate sizes for SD capacity
void initSizes() {
  if (cardCapacityMB <= 6) {
    sdError("Card is too small.");
  } else if (cardCapacityMB <= 16) {
    sectorsPerCluster = 2;
  } else if (cardCapacityMB <= 32) {
    sectorsPerCluster = 4;
  } else if (cardCapacityMB <= 64) {
    sectorsPerCluster = 8;
  } else if (cardCapacityMB <= 128) {
    sectorsPerCluster = 16;
  } else if (cardCapacityMB <= 1024) {
    sectorsPerCluster = 32;
  } else if (cardCapacityMB <= 32768) {
    sectorsPerCluster = 64;
  } else {
    // SDXC cards
    sectorsPerCluster = 128;
  }

  cout << pstr("Blocks/Cluster: ") << int(sectorsPerCluster) << endl;
  // set fake disk geometry
  sectorsPerTrack = cardCapacityMB <= 256 ? 32 : 63;

  if (cardCapacityMB <= 16) {
    numberOfHeads = 2;
  } else if (cardCapacityMB <= 32) {
    numberOfHeads = 4;
  } else if (cardCapacityMB <= 128) {
    numberOfHeads = 8;
  } else if (cardCapacityMB <= 504) {
    numberOfHeads = 16;
  } else if (cardCapacityMB <= 1008) {
    numberOfHeads = 32;
  } else if (cardCapacityMB <= 2016) {
    numberOfHeads = 64;
  } else if (cardCapacityMB <= 4032) {
    numberOfHeads = 128;
  } else {
    numberOfHeads = 255;
  }
}
Beispiel #20
0
ws_result wscString::Concat(wsiString ** ret, wsiString * str) const
{
    ws_ptr<wsiString> strAdd (str);
    const ws_int len1 = GetLength();
    const ws_int len2 = strAdd->GetLength();
    const ws_char * const buf1 = GetBuffer();
    const ws_char * const buf2 = strAdd->GetBuffer();

    ws_ptr<wsiStringService> strServ;
    wscString::GetStringService( &strServ );
    ws_ptr<wsiStringRW> strRW;
    strServ->AllocateString( &strRW , len1+len2 , buf1 , len1 );
    ws_char * const buf = strRW->GetBufferRW();
    wspr::ws_memcpy( buf+len1 , buf2 , len2 );
    strRW->SetLength( len1 + len2 );

    ws_ptr<wsiString> pstr( strRW );
    pstr.CopyTo( ret );
    return ws_result( WS_RLT_SUCCESS );
}
Beispiel #21
0
void
pfnc(io *fd, thread *t)
{
	int i;
	void (*fn)(void) = t->code[t->pc].f;
	list *a;

	pfmt(fd, "pid %d cycle %p %d ", getpid(), t->code, t->pc);
	for (i = 0; fname[i].f; i++) 
		if (fname[i].f == fn) {
			pstr(fd, fname[i].name);
			break;
		}
	if (!fname[i].f)
		pfmt(fd, "%p", fn);
	for (a = t->argv; a; a = a->next) 
		pfmt(fd, " (%v)", a->words);
	pchr(fd, '\n');
	flush(fd);
}
Beispiel #22
0
static void handle_loopfinal(void* ploop) {

  uv_loop_t* loop;
  int result;

  loop = (uv_loop_t*)ploop;
  result = loop->raw_loopcb(loop->raw_param);

  if (result) {
    mbed::util::FunctionPointer1<void, void*> pstr(handle_loopfinal);
    minar::Scheduler::postCallback(pstr.bind(ploop))
                        .tolerance(minar::milliseconds(1))
                        .delay(minar::milliseconds(1))
                        ;
  }
  else {
    result = loop->raw_finalcb(loop->raw_param);
    if (result == 0)
      tuv__run_clear(loop);
  }
}
Beispiel #23
0
PCXMLObject CXMLObject::GetObject ( cpstr Tag, int objNo )  {
// allow for "tag1>tag2>tag3>..."
PCXMLObject XMLObject;
int         i,j,k,l;
pstr        p,p1;
  XMLObject = this;
  if (Tag)  {
    p = pstr(Tag);
    do  {
      p1 = p;
      l  = 0;
      while (*p1 && (*p1!='>'))  {
        p1++;
        l++;
      }
      if (l>0)  {
        k = -1;
        j = 0;
        for (i=0;(i<XMLObject->nObjects) && (k<0);i++)
          if (XMLObject->object[i])  {
            if (!strncmp(XMLObject->object[i]->objTag,p,l))  {
              j++;
              if (j==objNo)  k = i;
            }
          }
        if (k<0)  {
          XMLObject = NULL;
          l = 0;
        } else  {
          XMLObject = XMLObject->object[k];
          if (*p1)  p = p1 + 1;
              else  l = 0;
        }
      }
    } while (l>0);
  }
  return XMLObject;
}
Beispiel #24
0
// Copy in the next line of text from the file, and scrub away non-graphic
// characters (replacing them with ' '). We leave characters in the range 32-126
// as well as 9-13.
void Lexer::MoveCursorToNextLine() {
  assert(!ifs.eof());
  std::string temp;
  std::getline(ifs, temp);

  // Check for null characters in line
  size_t line_length = temp.size();
  for (size_t i = 0; i < line_length; ++i) {
    if (temp[i] == '\0') {
      temp[i] = ' ';
      ErrorLog::NullCharInSrc(cursor);
    } else if (IsNonGraphic(temp[i])) {
      temp[i] = ' ';
      ErrorLog::NonGraphicCharInSrc(cursor);
    }
  }

  cursor.offset = 0;
  cursor.line   = pstr(temp.c_str());

  ++cursor.line_num;
  source_file_->lines.push_back(cursor.line);
}
static void parse_1(const char *start, const pdesc *inf, const char **str, int emode)
{
  const char *p = *str;
  const char *s = p;
  int depth = 0;
  while(*p) {
    char c = *p++;
    if(!depth && ((c == ',' && emode == ',') || (c == ')' && emode == ')'))) {
      if(s != p-1)
	pstr(s, p-1);
      *str = p;
      return;
    }
    if(c == '(')
      depth++;
    else if(c == ')') {
      depth--;
      if(depth < 0) {
	if(emode == ',')
	  fprintf(stderr, "Parse error, missing parameter in '%s'.\n", start);
	else
	  fprintf(stderr, "Parse error, unbalanced parenthesis in '%s'.\n", start);
	exit(1);
      }
    } else if(c == '%' && ((*p >= 'a' && *p <= 'z') || (*p >= '0' && *p <= '9'))) {
      char buf[4096];
      char *pp = buf;
      int i, j;
      int pos;

      if(s != p-1)
	pstr(s, p-1);

      while((*p >= 'a' && *p <= 'z') || (*p >= '0' && *p <= '9'))
	*pp++ = *p++;
      *pp = 0;
      for(i=0; inf[i].opt && strcmp(buf, inf[i].opt); i++);
      if(!inf[i].opt) {
	fprintf(stderr, "Parse error, unhandled parameter %%%s\n", buf);
	exit(1);
      }

      pos = parse_count++;
      parse_res[pos].start = 0;
      parse_res[pos].size = 0;
      parse_res[pos].id = inf[i].id;
      parse_res[pos].pcount = inf[i].pcount;

      if(inf[i].pcount) {
	if(*p != '(') {
	  fprintf(stderr, "Parse error, missing opening parenthesis on %%%s\n", buf);
	  exit(1);
	} else
	  p++;
      }

      *str = p;

      for(j=0; j != inf[i].pcount; j++) {
	parse_res[pos].ppos[j] = parse_count;
	parse_1(start, inf, str, j == inf[i].pcount-1 ? ')' : ',');
      }
      p = *str;
      parse_res[pos].ppos[j] = parse_count;
      s = p;
    }
  }
  if(s != p)
    pstr(s, p);
  *str = p;
  switch(emode) {
  case 0:
    return;
  case ',':
    fprintf(stderr, "Parse error, missing parameter at end of string in '%s'.\n", start);
    exit(1);
  case ')':
    fprintf(stderr, "Parse error, missing closing parenthesis at end of string in '%s'.\n", start);
    exit(1);
  }
}
Beispiel #26
0
/*! Create LineChunk from fetched data.
 *  The DXF line pattern description is mapped to a 16 bit stipple pattern
 *  suitable for OpenGL line stippling. This mapping only approximately
 *  resembles the DXF line pattern.
 *
 *  \todo 
 *	Currently it's not checked, whether the fetched data is consistent!
 */
DXFResult DXFLtype::endEntity(void)
{
	if(_linetypeMapP->find(_name) != _linetypeMapP->end())
	{
		FWARNING(("DXF Loader: before line %d: "
				  "LTYPE entity '%s' already exists. "
				  "Overwriting with new one!\n",
				  DXFRecord::getLineNumber(),
				  _name.c_str()
				 ));
	}

	// Do consistency checks
	Real32 checkedPatternLen = 0.0;
	for(std::vector<Real64>::iterator itr = _elementLen.begin();
		itr != _elementLen.end();
		++ itr)
	{
		checkedPatternLen += osgabs(*itr);
	}
	
	if(osgabs(checkedPatternLen - _patternLen) > Eps)
	{
		FWARNING(("DXF Loader: before line %d: "
				  "LTYPE entity defines inconsistent pattern lenght!\n",
				  DXFRecord::getLineNumber()
				 ));
		// we go on, but will use consistent data: checkedPatternLen
	}

	if(_nElements != _elementLen.size())
	{
		FWARNING(("DXF Loader: before line %d: "
				  "LTYPE entity declares %d pattern elements but provides %d!\n",
				  DXFRecord::getLineNumber(),
				  _nElements,
				  _elementLen.size()
				 ));
		// we go on, but will use consistent data: _elementLen.size()
	}

	UInt16 pattern = 0;
	LineChunkPtr linetype = LineChunk::create();	
	beginEditCP(linetype);
	{		
//		linetype->setWidth(1);
		if(_elementLen.size() != 0)
		{
			// Build OpenGL 16 bit stipple pattern: for each bit calculate, which
			// pattern element it belongs to and set it if the pattern element is
			// positive, otherwise leave it unset.
			Real32 s = checkedPatternLen/16.0;
			UInt8 j = 0;
			Real32 elementLenSum = osgabs(_elementLen[j]);
			for(UInt8 i = 0;
				i < 16;
				++ i)
			{
				if(elementLenSum < (0.5 + i) * s && j < _elementLen.size())
				{
					++ j;
					elementLenSum += osgabs( _elementLen[j] );
				}
				if( _elementLen[j] > 0.0)
					pattern |= 1<<i;
			}
			linetype->setStippleRepeat(1);
			linetype->setStipplePattern(pattern);	
		}
		linetype->setSmooth(true);  //TODO: make this configurable by an option?
	}
	endEditCP(linetype);
	
#if 1 // DEBUG TODO: raus?!?!
	std::string pstr("");
	for(UInt8 i=0; i<16; ++i)
		pstr += (pattern & (1<<i)) ? "1" : "0";
	FDEBUG(("DXFLtype::endEntity(): pattern '%s' = %s\n",
			_name.c_str(),
			pstr.c_str()));
#endif // DEBUG
	(*_linetypeMapP)[_name] = linetype;

	return DXFStateContinue;
}
Beispiel #27
0
	void ItemSetBuilder::report(bool graph) const {
		std::ofstream file, gfile;
		file.open("report\\lalr_states", std::ios::trunc);
		if (graph) {
			gfile.open("report\\graph\\lalr.dot", std::ios::trunc);
		}
		if (file.is_open()) {
			if (gfile.is_open()) {
				gfile << "digraph lalr_graph {\n" << "node [shape=record];\n";
			}
			std::string dot = "[>";
			for (auto& p : m_sorted) {
				auto& state = *p.second;
				file << "[state " << state.m_id << "]\n";
				std::string gitems;
				for (auto& item : state.m_closure) {
					if (!item.is_kernel()) continue;
					auto& p = m_grammar.get_production(item.production_id());
					std::string pstr(p[0].name());
					pstr.append(" ==> ");
					for (std::size_t i = 0; i <= p.rhs_count(); i++) {
						if (i == item.dot()) {
							pstr.append(dot);
						}
						if (i < p.rhs_count()) {
							pstr.append(p[i + 1].name()).append(" ");
						}
					}
					file << ">\t" << std::setw(20) << pstr << "\n\t\t";

					std::string lookaheads;
					auto cols = 4, col = 0;
					for (auto it = m_grammar.symbol_begin(); it != m_grammar.symbol_end(); it++) {
						if (item.lookaheads()[**it]) {
							file << **it << "\t";
							lookaheads.append((**it).name()).append(" ");
							if (++col == cols) {
								col = 0;
								lookaheads.append("\\n");
							}
						}
					}
					file << "\n";

					std::regex re("[|<>{}]");
					pstr = std::regex_replace(pstr, re, "\\$&");
					lookaheads = std::regex_replace(lookaheads, re, "\\$&");
					gitems.append("{ ").append(pstr).append(" | ")
						.append(lookaheads).append("}|");
				}
				file << '\n';
				if (gfile.is_open()) {
					if (gitems.size() > 0) {
						// remove the last '|'
						gitems.erase(gitems.size() - 1);
					}
					gfile << state.m_id << " [label=\"" << state.m_id << "|{"
						<< gitems << "}\"];\n";
				}

				for (auto& action : state.m_actions) {
					file << ">\t" << std::setw(30)
						<< std::left << m_grammar.get_symbol(action.first)
						<< std::right << action.second.type;
					if (action.second.type == ActionType::SHIFT
						|| action.second.type == ActionType::GOTO) {
						file << std::setw(10) << "[ state " << action.second.value << " ]";
						if (gfile.is_open()) {
							gfile << state.m_id << " -> " << action.second.value
								<< " [label=\"" << m_grammar.get_symbol(action.first) << "\"];\n";
						}
					}
					else if (action.second.type == ActionType::REDUCE) {
						file << std::setw(10) << "[ " << m_grammar.get_production(action.second.value) << " ]";
					}
					file << '\n';
				}
				file << '\n';
			}
			file << "Total conflicts: " << m_conflict_count << '\n';
			if (gfile.is_open()) {
				gfile << "}\n";
			}
		}
		file.close();
		if (graph) {
			gfile.close();
		}
	}
Beispiel #28
0
int
CIFSsession(Session *s)
{
	char os[64], *q;
	Rune r;
	Pkt *p;
	enum {
		mycaps = CAP_UNICODE | CAP_LARGE_FILES | CAP_NT_SMBS |
			CAP_NT_FIND | CAP_STATUS32,
	};

	s->seqrun = 1;	/* activate the sequence number generation/checking */

	p = cifshdr(s, nil, SMB_COM_SESSION_SETUP_ANDX);
	p8(p, 0xFF);			/* No secondary command */
	p8(p, 0);			/* Reserved (must be zero) */
	pl16(p, 0);			/* Offset to next command */
	pl16(p, MTU);			/* my max buffer size */
	pl16(p, 1);			/* my max multiplexed pending requests */
	pl16(p, 0);			/* Virtual connection # */
	pl32(p, 0);			/* Session key (if vc != 0) */


	if((s->secmode & SECMODE_PW_ENCRYPT) == 0) {
		pl16(p, utflen(Sess->auth->resp[0])*2 + 2); /* passwd size */
		pl16(p, utflen(Sess->auth->resp[0])*2 + 2); /* passwd size (UPPER CASE) */
		pl32(p, 0);			/* Reserved */
		pl32(p, mycaps);
		pbytes(p);

		for(q = Sess->auth->resp[0]; *q; ){
			q += chartorune(&r, q);
			pl16(p, toupperrune(r));
		}
		pl16(p, 0);

		for(q = Sess->auth->resp[0]; *q; ){
			q += chartorune(&r, q);
			pl16(p, r);
		}
		pl16(p, 0);
	}else{
		pl16(p, Sess->auth->len[0]);	/* LM passwd size */
		pl16(p, Sess->auth->len[1]);	/* NTLM passwd size */
		pl32(p, 0);			/* Reserved  */
		pl32(p, mycaps);
		pbytes(p);

		pmem(p, Sess->auth->resp[0], Sess->auth->len[0]);
		pmem(p, Sess->auth->resp[1], Sess->auth->len[1]);
	}

	pstr(p, Sess->auth->user);	/* Account name */
	pstr(p, Sess->auth->windom);	/* Primary domain */
	pstr(p, "plan9");		/* Client OS */
	pstr(p, argv0);			/* Client LAN Manager type */

	if(cifsrpc(p) == -1){
		free(p);
		return -1;
	}

	g8(p);				/* Reserved (0) */
	gl16(p);			/* Offset to next command wordcount */
	Sess->isguest = gl16(p) & 1;	/* logged in as guest */

	gl16(p);
	gl16(p);
	/* no security blob here - we don't understand extended security anyway */
	gstr(p, os, sizeof os);
	s->remos = estrdup9p(os);

	free(p);
	return 0;
}
Beispiel #29
0
void build_in_dht()
{
#ifdef DHT

	static bool running = false;
	static mutex mut;
	static dht::DhtRunner ht;
	static int port = 4443;
	
	if (!running)
	{
		running = true;
		int port = 4443;
		dout << "firing up DHT on port " << port << endl;
		// Launch a dht node on a new thread, using a
		// generated RSA key pair, and listen on port 4222.
		ht.run(port, dht::crypto::generateIdentity(), true);

		// Join the network through any running node,
		// here using a known bootstrap node.
		ht.bootstrap("127.0.0.1", "4444");

		// put some data on the dht
		std::vector<uint8_t> some_data(5, 10);
		ht.put("unique_key", some_data);

		// put some data on the dht, signed with our generated private key
		ht.putSigned("unique_key_42", some_data);

	}

	auto ht_ = &ht;

	EEE;	
	
	string bu = "http://idni.org/dht#put";
	auto bui = dict.set(mkiri(pstr(bu)));

	builtins[bui].push_back(
		[bu, entry, ht_](Thing *dummy, Thing *x) mutable {
		setproc(bu);
		TRACE_ENTRY;
		dout <<"sssss" << endl;
		switch(entry){
		case 0:
			x = getValue(x);
			
			if(is_node(*x))
			{
				node n = dict[get_node(*x)];
				string v = *n.value;
				string key,val;

				if (n._type == node::IRI)
				{
					if (has(mykb->first, v))
					{
						key = "root_graph_" + v;
						stringstream ss;
						ss << mykb->first[v];
						val = ss.str();
					}
					else
					{
						string h = strhash(v);
						key = "root_iri_" + h;
						val = v;
					}
				}
				else if (n._type == node::LITERAL)
				{
					string h = strhash(v);
					key = "root_lit_" + h;
					val = v;
				}
				else
				{
					dout << "nope." << endl;
					DONE;
				}
				dout << "putting " << key << "=" << val << endl;
				ht_->put(key, val);
				
			}
			else
				dout << "nope." << endl;
			
						
			END;
		}
	});
	
	
	
	bu = "http://idni.org/dht#dbg";
	bui = dict.set(mkiri(pstr(bu)));

	builtins[bui].push_back(
		[bu, entry, ht_](Thing *dummy, Thing *x) mutable {
		setproc(bu);
		TRACE_ENTRY;
		
		switch(entry){
		case 0:
			x = getValue(x);
					
			if(is_node(*x))
			{
				node n = dict[get_node(*x)];
				string v = *n.value;
				if (v == "on")
				{
					MSG("dht dbg on");
					enableDhtLogging(*ht_);
				}
				else{
					MSG("dht dbg off");
					ht_->setLoggers(dht::NOLOG, dht::NOLOG, dht::NOLOG);
				}
			}
						
			END;
		}
	});

	bu = "http://idni.org/dht#setPort";
	bui = dict.set(mkiri(pstr(bu)));

	builtins[bui].push_back(
		[bu, entry, ht_](Thing *dummy, Thing *x) mutable {
		setproc(bu);
		TRACE_ENTRY;
		
		switch(entry){
		case 0:
			x = getValue(x);
					
			if(is_node(*x))
			{
				node n = dict[get_node(*x)];
				string v = *n.value;
				if (v == "on")
				{
					MSG("dht dbg on");
					enableDhtLogging(*ht_);
				}
				else{
					MSG("dht dbg off");
					ht_->setLoggers(dht::NOLOG, dht::NOLOG, dht::NOLOG);
				}
			}
						
			END;
		}
	});


    // get data from the dht
    ht_->get("other_unique_key", [](const std::vector<std::shared_ptr<dht::Value>>& values) {
        // Callback called when values are found
        for (const auto& value : values)
            dout << "Found value: " << *value << std::endl;
        return true; // return false to stop the search
    });
#endif

}
Beispiel #30
0
void
pexpr(Node *n)
{
	Node *r, *l;

	if(n == 0)
		return;

	r = n->right;
	l = n->left;

	switch(n->op) {
	case ONAME:
		Bprint(bout, "%s", n->sym->name);
		break;
	case OCONST:
		switch(n->type) {
		case TINT:
			Bprint(bout, "%lld", n->ival);
			break;
		case TFLOAT:
			Bprint(bout, "%g", n->fval);
			break;
		case TSTRING:
			pstr(n->string);
			break;
		case TLIST:
			break;
		}
		break;
	case OMUL:
	case ODIV:
	case OMOD:
	case OADD:
	case OSUB:
	case ORSH:
	case OLSH:
	case OLT:
	case OGT:
	case OLEQ:
	case OGEQ:
	case OEQ:
	case ONEQ:
	case OLAND:
	case OXOR:
	case OLOR:
	case OCAND:
	case OCOR:
		Bputc(bout, '(');
		pexpr(l);
		Bprint(bout, binop[n->op]);
		pexpr(r);
		Bputc(bout, ')');
		break;
	case OASGN:
		pexpr(l);
		Bprint(bout, binop[n->op]);
		pexpr(r);
		break;
	case OINDM:
		Bprint(bout, "*");
		pexpr(l);
		break;
	case OEDEC:
		Bprint(bout, "--");
		pexpr(l);
		break;
	case OEINC:
		Bprint(bout, "++");
		pexpr(l);
		break;
	case OPINC:
		pexpr(l);
		Bprint(bout, "++");
		break;
	case OPDEC:
		pexpr(l);
		Bprint(bout, "--");
		break;
	case ONOT:
		Bprint(bout, "!");
		pexpr(l);
		break;
	case OLIST:
		pexpr(l);
		if(r) {
			Bprint(bout, ",");
			pexpr(r);
		}
		break;
	case OCALL:
		pexpr(l);
		Bprint(bout, "(");
		pexpr(r);
		Bprint(bout, ")");
		break;
	case OCTRUCT:
		Bprint(bout, "{");
		pexpr(l);
		Bprint(bout, "}");
		break;
	case OHEAD:
		Bprint(bout, "head ");
		pexpr(l);
		break;
	case OTAIL:
		Bprint(bout, "tail ");
		pexpr(l);
		break;
	case OAPPEND:
		Bprint(bout, "append ");
		pexpr(l);
		Bprint(bout, ",");
		pexpr(r);
		break;
	case ODELETE:
		Bprint(bout, "delete ");
		pexpr(l);
		Bprint(bout, ",");
		pexpr(r);
		break;
	case ORET:
		Bprint(bout, "return ");
		pexpr(l);
		break;
	case OINDEX:
		pexpr(l);
		Bprint(bout, "[");
		pexpr(r);
		Bprint(bout, "]");
		break;
	case OINDC:
		Bprint(bout, "@");
		pexpr(l);
		break;
	case ODOT:
		pexpr(l);
		Bprint(bout, ".%s", n->sym->name);
		break;
	case OFRAME:
		Bprint(bout, "%s:%s", n->sym->name, l->sym->name);
		break;
	case OCAST:
		Bprint(bout, "(%s)", n->sym->name);
		pexpr(l);
		break;
	case OFMT:
		pexpr(l);
		Bprint(bout, "\\%c", (int)r->ival);
		break;
	case OEVAL:
		Bprint(bout, "eval ");
		pexpr(l);
		break;
	case OWHAT:
		Bprint(bout, "whatis");
		if(n->sym)
			Bprint(bout, " %s", n->sym->name);
		break;
	}
}