Ejemplo n.º 1
0
static FrRegExElt *compile_class(const char *&re, FrList *&classes)
{
   assertq(*re == FrRE_CLASS_BEG) ;
   re++ ;
   const char *name_end = strchr(re,FrRE_CLASS_END) ;
   if (name_end)
      {
      char name[FrMAX_SYMBOLNAME_LEN+1] ;
      size_t namelen = name_end - re ;
      if (namelen >= sizeof(name))
	 namelen = sizeof(name) - 1 ;
      memcpy(name,re,namelen) ;
      name[namelen] = '\0' ;
      re = name_end + 1 ;
      FrRegExClass *class_members = new FrRegExClass ;
      if (!class_members)
	 return 0 ;			// out of memory!
      FrSymbol *namesym = FrSymbolTable::add(name) ;
      FrList *cl = (FrList*)classes->assoc(namesym) ;
      if (cl)
	 {
	 // add to list of instances of this class
	 FrList *members = cl->rest() ;
	 pushlist((FrObject*)class_members,members) ;
	 cl->replacd(members) ;
	 }
      else
	 {
	 // create a new list of class instances
	 pushlist(new FrList(namesym,(FrObject*)class_members),classes) ;
	 }
      return new FrRegExElt(class_members) ;
      }
   return 0 ;
}
Ejemplo n.º 2
0
/*
 * get command line flags, initialize keywords & traps.
 * get values from environment.
 * set $pid, $cflag, $*
 * fabricate bootstrap code and start it (*=(argv);. /usr/lib/rcmain $*)
 * start interpreting code
 */
int
main(int argc, char *argv[])
{
	code bootstrap[32];
	char num[12], *rcmain;
	int i;
	
	/* needed for rcmain later */
	putenv("PLAN9", unsharp("#9"));
	argc = getflags(argc, argv, "ftjSsrdiIlxepvVc:1m:1[command]", 1);
	if(argc==-1)
		usage("[file [arg ...]]");
	if(argv[0][0]=='-')
		flag['l'] = flagset;
	if(flag['I'])
		flag['i'] = 0;
	else if(flag['i']==0 && argc==1 && Isatty(0)) flag['i'] = flagset;
	rcmain = flag['m'] ? flag['m'][0] : Rcmain();
	err = openfd(2);
	kinit();
	Trapinit();
	Vinit();
	inttoascii(num, mypid = getpid());
	pathinit();
	setvar("pid", newword(num, (word *)0));
	setvar("cflag", flag['c']?newword(flag['c'][0], (word *)0)
				:(word *)0);
	setvar("rcname", newword(argv[0], (word *)0));
	i = 0;
	bootstrap[i++].i = 1;
	bootstrap[i++].f = Xmark;
	bootstrap[i++].f = Xword;
	bootstrap[i++].s="*";
	bootstrap[i++].f = Xassign;
	bootstrap[i++].f = Xmark;
	bootstrap[i++].f = Xmark;
	bootstrap[i++].f = Xword;
	bootstrap[i++].s="*";
	bootstrap[i++].f = Xdol;
	bootstrap[i++].f = Xword;
	bootstrap[i++].s = rcmain;
	bootstrap[i++].f = Xword;
	bootstrap[i++].s=".";
	bootstrap[i++].f = Xsimple;
	bootstrap[i++].f = Xexit;
	bootstrap[i].i = 0;
	start(bootstrap, 1, (var *)0);
	/* prime bootstrap argv */
	pushlist();
	argv0 = strdup(argv[0]);
	for(i = argc-1;i!=0;--i) pushword(argv[i]);
	for(;;){
		if(flag['r'])
			pfnc(err, runq);
		runq->pc++;
		(*runq->code[runq->pc-1].f)();
		if(ntrap)
			dotrap();
	}
}
Ejemplo n.º 3
0
static FrBool collect_symbols(const FrObject *obj, va_list args)
{
   FrSymbol *sym = (FrSymbol*)obj ;
   FrVarArg(FrList **,symlist) ;
   pushlist(sym,*symlist) ;
   return True ;
}
Ejemplo n.º 4
0
bool FrTextSpans::addMetaData(FrSymbol *key, const FrObject *value)
{
   FrStructField *field = m_metadata.getField(key) ;
   if (!field)
      return setMetaData(key,value) ;
   FrObject *oldvalue = field->get() ;
   if (oldvalue)
      {
      if (oldvalue->consp())
	 {
	 FrList *list = (FrList*)oldvalue ;
	 if (value && value->consp())
	    {
	    FrList *newvalue = ((FrList*)value)->difference(list) ;
	    list = newvalue->nconc(list) ;
	    }
	 else if (!list->member(value,::equal))
	    pushlist(value?value->deepcopy():0,list) ;
	 field->set(list) ;
	 }
      else
	 return false ;
      }
   else if (value && value->consp())
      field->set(value->deepcopy()) ;
   else
      field->set(new FrList(value?value->deepcopy():0)) ;
   return true ;
}
Ejemplo n.º 5
0
bool FrTextSpans::insertMetaData(FrSymbol *key, FrObject *value,
				 bool copy)
{
   FrStructField *field = m_metadata.getField(key) ;
   if (!field)
      return setMetaData(key,value,copy) ;
   FrObject *oldvalue = field->get() ;
   if (oldvalue)
      {
      if (!oldvalue->consp())
	 {
	 oldvalue = new FrList(oldvalue) ;
	 field->set(oldvalue) ;
	 }
      FrList *list = (FrList*)oldvalue ;
      if (!list->member(value,::equal))
	 {
	 pushlist(value&&copy?value->deepcopy():value,list) ;
	 field->set(list) ;
	 }
      }
   else if (value && value->consp())
      field->set(copy?value->deepcopy():value) ;
   else
      field->set(new FrList((value&&copy)?value->deepcopy():value)) ;
   return true ;
}
Ejemplo n.º 6
0
FrList *FrTextSpans::printable() const
{
   FrList *result = 0 ;
   for (size_t i = 0 ; i < spanCount() ; i++)
      {
      pushlist(getSpan(i)->printable(),result) ;
      }
   FrList *meta_fields = m_metadata.fieldNames() ;
   if (meta_fields)
      {
      pushlist(m_metadata.deepcopy(),result) ;
      meta_fields->freeObject() ;
      }
   result = listreverse(result) ;
   pushlist(new FrString(originalString()),result) ;
   return result ;
}
Ejemplo n.º 7
0
FrList *FrTextSpan::printable() const
{
   FrList *span = 0 ;
   const FrStruct *meta = metaData() ;
   FrList *fields = meta ? meta->fieldNames() : 0 ;
   while (fields)
      {
      FrSymbol *key = (FrSymbol*)poplist(fields) ;
      FrObject *data = meta->get(key) ;
      if (data)
	 {
	 data = data->deepcopy() ;
	 if (!data->consp())
	    data = new FrList(data) ;
	 FrList *datalist = (FrList*)data ;
	 pushlist(key,datalist) ;
	 pushlist(datalist,span) ;
	 }
      }
   pushlist(new FrFloat(weight()),span) ;
   pushlist(new FrFloat(score()),span) ;
   pushlist(new FrString(text()),span) ;
   pushlist(new FrInteger(end()),span) ;
   pushlist(new FrInteger(start()),span) ;
   return span ;
}
Ejemplo n.º 8
0
static void symtab_menu(ostream &out, istream &in)
{
   int choice ;
   static FrList *symtabs = 0 ;
   FrCons *newtab ;
   FrSymbolTable *old_symtab = FrSymbolTable::current() ;

   do {
      FrSymbolTable::selectDefault() ;  // read into default symbol table
      choice = display_menu(out,in,true,5,
			    "FrSymbol Table Options:",
			    "\t1. Select default symbol table\n"
			    "\t2. Create a new symbol table\n"
			    "\t3. FrList symbol tables\n"
			    "\t4. Select symbol table by name\n"
			    "\t5. Destroy a symbol table\n"
			    ) ;
      old_symtab->select() ;	// restore symbol table after reading input
      switch (choice)
	 {
	 case 0:
	    // do nothing
	    break ;
	 case 1:
	    FrSymbolTable::selectDefault() ;
	    break ;
	 case 2:
	    newtab = symtab_create(in,symtabs) ;
	    if (newtab)
	       pushlist(newtab,symtabs) ;
	    break ;
	 case 3:
	    out << "\nCurrent symbol tables: (default)" ;
	    FrList *sym ;
	    for (sym = symtabs ; sym ; sym = sym->rest())
	       out << ", " << sym->car()->car() ;
	    out << endl << endl ;
	    break ;
	 case 4:
	    old_symtab = symtab_select(in,symtabs) ;
	    break ;
	 case 5:
	    symtabs = symtab_delete(in,symtabs) ;
	    break ;
	 default:
	    FrMissedCase("symtab_menu") ;
	    break ;
	 }
      } while (choice != 0) ;
   old_symtab->select() ;
   return ;
}
Ejemplo n.º 9
0
static FrList *find_files_Windows(const char *directory, const char *mask,
				   const char *extension,
				   bool strip_extension = true)
{
   if (!mask)
      mask = "*" ;
   if (!extension)
      extension = "*" ;
   struct _finddata_t ffblk ;
   FrList *files = 0 ;
   size_t dirlen = strlen(directory) ;
   size_t masklen = strlen(mask) + 1 ;
   size_t buflen = dirlen + masklen + strlen(extension) + 2 ;
   FrLocalAlloc(char,fullname,1024,buflen) ;
   if (!fullname)
      {
      FrNoMemory("while getting disk directory") ;
      return 0 ;
      }
   memcpy(fullname,directory,dirlen) ;
   fullname[dirlen++] = '/' ;
   memcpy(fullname+dirlen,mask,masklen) ;
   if (*extension)
      {
      strcat(fullname,".") ;
      strcat(fullname,extension) ;
      }
   ffblk.attrib = _A_NORMAL ;
   long searchhandle = _findfirst(fullname,&ffblk) ;
//!!!
   if (searchhandle == -1)
      {
      FrLocalFree(fullname) ;
      return 0 ;
      }
   int found = 1 ;
   while (found > 0)
      {
      char *period = strip_extension ? strchr(ffblk.name,'.')
	                             : strchr(ffblk.name,'\0') ;
      if (period)
	 {
	 int len = period - ffblk.name ;
	 pushlist(new FrString(ffblk.name,len),files) ;
	 }
      found = _findnext(searchhandle,&ffblk) ;
      }
   _findclose(searchhandle) ;
   FrLocalFree(fullname) ;
   return files->sort(string_compare) ;
}
Ejemplo n.º 10
0
void
globlist(void)
{
	word *a;
	globv = 0;
	globlist1(runq->argv->words);
	poplist();
	pushlist();
	if(globv){
		for(a = globv;a->next;a = a->next);
		a->next = runq->argv->words;
		runq->argv->words = globv;
	}
}
Ejemplo n.º 11
0
static bool prefix_match(const FrSymbol *name, FrObject * /*info*/, va_list args)
{
   //HashEntryVFrame* entry = (HashEntryVFrame*)info ;
   FrVarArg(const char *,prefix) ;
   FrVarArg(size_t,prefixlen) ;
   FrVarArg(FrList**,matches) ;
   if (name)
      {
      if (memcmp(name->symbolName(),prefix,prefixlen) == 0)
	 {
	 pushlist(name,*matches) ;
	 }
      }
   return true ;
}
Ejemplo n.º 12
0
static bool FramepaC_to_FrameKit_slot(const FrFrame *frame,
				      const FrSymbol *slotname,
				      va_list args)
{
   FrList **slots ;
   FrList *temp_FrameKit_facets = nullptr ;

   do_facets(frame,slotname,FramepaC_to_FrameKit_facet,&temp_FrameKit_facets) ;
   if (temp_FrameKit_facets)
      {
      pushlist(slotname,temp_FrameKit_facets) ;
      slots = va_arg(args,FrList **) ;
      *slots = (*slots)->nconc(new FrList(temp_FrameKit_facets)) ;
      }
   return true ;  // successful
}
Ejemplo n.º 13
0
static bool FramepaC_to_FrameKit_facet(const FrFrame *frame,
				       const FrSymbol *slot,
				       const FrSymbol *facet, va_list args)
{
   FrList **facets ;
   const FrList *fillers = frame->getImmedFillers(slot,facet) ;

   if (fillers)
      {
      FrList *flist = (FrList*)fillers->deepcopy() ;

      pushlist(symbolCOMMON,flist) ;
      flist = new FrList(facet,flist) ;
      facets = va_arg(args,FrList **) ;
      *facets = (*facets)->nconc(new FrList(flist)) ;
      }
   return true ;  // successful
}
Ejemplo n.º 14
0
bool FrTextSpan::addMetaData(FrSymbol *key, const FrObject *value)
{
   if (!metaData())
      {
      setMetaData(new FrStruct(FrSymbolTable::add(METADATA_TYPENAME))) ;
      if (!metaData())
	 return false ;
      }
   FrObject *oldvalue = m_metadata->get(key) ;
   if (oldvalue)
      {
      if (oldvalue->consp())
	 {
	 FrList *list = (FrList*)oldvalue->deepcopy() ;
	 if (value && value->consp())
	    {
	    FrList *newvalue = ((FrList*)value)->difference(list) ;
	    list = newvalue->nconc(list) ;
	    m_metadata->put(key,list,false) ;
	    }
	 else if (!list->member(value,::equal))
	    {
	    pushlist(value?value->deepcopy():0,list) ;
	    m_metadata->put(key,list,false) ;
	    }
	 else
	    free_object(list) ;
	 }
      else
	 return false ;
      }
   else if (value && value->consp())
      m_metadata->put(key,value->deepcopy(),false) ;
   else
      m_metadata->put(key,new FrList(value?value->deepcopy():0),false) ;
   return true ;
}
Ejemplo n.º 15
0
    char *field_(const char *name, int color, int length, int height, const char *initval, int initmode, int fieldtype = FIELDEDIT)
    {	
        editor *e = useeditor(name, initmode, false, initval); // generate a new editor if necessary
        if(layoutpass)
        {
            if(initval && e->mode==EDITORFOCUSED && (e!=currentfocus() || fieldmode == FIELDSHOW))
            {
                if(strcmp(e->lines[0].text, initval)) e->clear(initval);
            }
            e->linewrap = (length<0);
            e->maxx = (e->linewrap) ? -1 : length;
            e->maxy = (height<=0)?1:-1;
            e->pixelwidth = abs(length)*FONTW;
            if(e->linewrap && e->maxy==1) 
            {
                int temp;
                text_bounds(e->lines[0].text, temp, e->pixelheight, e->pixelwidth); //only single line editors can have variable height
            }
            else 
                e->pixelheight = FONTH*max(height, 1); 
        }
        int h = e->pixelheight;
        int w = e->pixelwidth + FONTW;
        
        bool wasvertical = isvertical();
        if(wasvertical && e->maxy != 1) pushlist();
        
        char *result = NULL;
        if(visible() && !layoutpass)
        {
            e->rendered = true;

            bool hit = ishit(w, h);
            if(hit) 
            {
                if(mousebuttons&G3D_DOWN) //mouse request focus
                {   
                    if(fieldtype==FIELDKEY) e->clear();
                    useeditor(name, initmode, true); 
                    e->mark(false);
                    fieldmode = fieldtype;
                } 
            }
            bool editing = (fieldmode != FIELDSHOW) && (e==currentfocus());
            if(hit && editing && (mousebuttons&G3D_PRESSED)!=0 && fieldtype==FIELDEDIT) e->hit(int(floor(hitx-(curx+FONTW/2))), int(floor(hity-cury)), (mousebuttons&G3D_DRAGGED)!=0); //mouse request position
            if(editing && ((fieldmode==FIELDCOMMIT) || (fieldmode==FIELDABORT) || !hit)) // commit field if user pressed enter or wandered out of focus 
            {
                if(fieldmode==FIELDCOMMIT || (fieldmode!=FIELDABORT && !hit)) result = e->currentline().text;
                e->active = (e->mode!=EDITORFOCUSED);
                fieldmode = FIELDSHOW;
            } 
            else fieldsactive = true;
            
            e->draw(curx+FONTW/2, cury, color, hit && editing);
            
            notextureshader->set();
            glDisable(GL_TEXTURE_2D);
            glDisable(GL_BLEND);
            if(editing) glColor3f(1, 0, 0);
            else glColor3ub(color>>16, (color>>8)&0xFF, color&0xFF);
            rect_(curx, cury, w, h, -1, true);
            glEnable(GL_TEXTURE_2D);
            glEnable(GL_BLEND);
            defaultshader->set();
        }
Ejemplo n.º 16
0
static FrList *find_files_Unix(const char *directory, const char *filemask,
			       const char *extension,
			       bool strip_extension = true)
{
   if (!extension)
      extension = "" ;
   if (!filemask)
      filemask = "*" ;
   size_t filelen = strlen(filemask) ;
   size_t extlen = strlen(extension) + 1 ;
   size_t masklen = filelen + extlen + 1 ;
   FrLocalAlloc(char,mask,1024,masklen) ;
   if (!mask)
      {
      FrNoMemory("while searching for files") ;
      return 0 ;
      }
   memcpy(mask,filemask,filelen+1) ;
   if (*extension)
      {
      mask[filelen++] = '.' ;
      memcpy(mask+filelen,extension,extlen) ;
      }
   FrList *files = 0 ;
   DIR *dirp = opendir(directory) ;
   if (dirp)
      {
      struct dirent *entry ;
      while ((entry = readdir(dirp)) != 0)
	 {
	 const char *name = entry->d_name ;
	 const char *m = mask ;
	 while (*name && *m && *m != '*' &&
		(*name == *m || *m == '?'))
	    {
	    name++ ;
	    m++ ;
	    }
	 bool match = false ;
	 if (*m == '*')
	    {
	    size_t tail = strlen(m+1) ;
	    size_t remaining = strlen(name) ;
	    if (tail <= remaining &&
		strcmp(name+remaining-tail,m+1) == 0)
	       match = true ;
	    }
	 else if (*m == *name)
	    match = true ;
	 if (match)
	    {
	    name = entry->d_name ;
	    size_t len = strlen(name) ;
	    if (strip_extension && *extension)
	       len -= (strlen(extension) + 1) ;
	    pushlist(new FrString(name,len), files) ;
	    }
	 }
      closedir(dirp) ;
      }
   FrLocalFree(mask) ;
   return files->sort(string_compare) ;
}
Ejemplo n.º 17
0
void
execdot(void)
{
	int iflag = 0;
	int fd;
	list *av;
	thread *p = runq;
	char *zero;
	static int first = 1;
	char file[512];
	word *path;
	if(first){
		dotcmds[0].i = 1;
		dotcmds[1].f = Xmark;
		dotcmds[2].f = Xword;
		dotcmds[3].s="0";
		dotcmds[4].f = Xlocal;
		dotcmds[5].f = Xmark;
		dotcmds[6].f = Xword;
		dotcmds[7].s="*";
		dotcmds[8].f = Xlocal;
		dotcmds[9].f = Xrdcmds;
		dotcmds[10].f = Xunlocal;
		dotcmds[11].f = Xunlocal;
		dotcmds[12].f = Xreturn;
		first = 0;
	}
	else
		eflagok = 1;
	popword();
	if(p->argv->words && strcmp(p->argv->words->word, "-i")==0){
		iflag = 1;
		popword();
	}
	/* get input file */
	if(p->argv->words==0){
		Xerror1("Usage: . [-i] file [arg ...]");
		return;
	}
	zero = strdup(p->argv->words->word);
	popword();
	fd=-1;
	for(path = searchpath(zero);path;path = path->next){
		strcpy(file, path->word);
		if(file[0])
			strcat(file, "/");
		strcat(file, zero);
		if((fd = open(file, 0))>=0) break;
		if(strcmp(file, "/dev/stdin")==0){	/* for sun & ucb */
			fd = Dup1(0);
			if(fd>=0)
				break;
		}
	}
	if(fd<0){
		pfmt(err, "%s: ", zero);
		setstatus("can't open");
		Xerror(".: can't open");
		return;
	}
	/* set up for a new command loop */
	start(dotcmds, 1, (struct var *)0);
	pushredir(RCLOSE, fd, 0);
	runq->cmdfile = zero;
	runq->cmdfd = openfd(fd);
	runq->iflag = iflag;
	runq->iflast = 0;
	/* push $* value */
	pushlist();
	runq->argv->words = p->argv->words;
	/* free caller's copy of $* */
	av = p->argv;
	p->argv = av->next;
	efree((char *)av);
	/* push $0 value */
	pushlist();
	pushword(zero);
	ndot++;
}
Ejemplo n.º 18
0
void
Xmark(void)
{
	pushlist();
}