/*
** returns the `main' position of an element in a table (that is, the index
** of its hash value)
*/
static Node *mainposition (const Table *t, const TValue *key)
{
    switch (ttype(key)) {
    case LUA_TNUMBER:
        return hashnum(t, nvalue(key));
    case LUA_TSTRING:
        return hashstr(t, rawtsvalue(key));
    case LUA_TBOOLEAN:
        return hashboolean(t, bvalue(key));
    case LUA_TLIGHTUSERDATA:
    case LUA_TROTABLE:
    case LUA_TLIGHTFUNCTION:
        return hashpointer(t, pvalue(key));
    default:
        return hashpointer(t, gcvalue(key));
    }
}
示例#2
0
void hash_at(struct hash *hash, const char *key, void **mem)
{
    unsigned i, h;
    struct hash_bucket *iter;

    h = hashstr(key, hash->max_size);

    for (i = 0; i < hash->buckets[h].length; ++i) {
        darray_at(&hash->buckets[h], i, (void **)&iter);
        if (!strcmp(iter->key, key)) {
            *mem = iter->mem;
            return;
        }
    }

    *mem = NULL;
}
示例#3
0
文件: go.c 项目: 8l/go-learn
static Import *
ilookup(char *name)
{
	int h;
	Import *x;

	h = hashstr(name) % NIHASH;
	for(x=ihash[h]; x; x=x->hash)
		if(x->name[0] == name[0] && strcmp(x->name, name) == 0)
			return x;
	x = mal(sizeof *x);
	x->name = strdup(name);
	x->hash = ihash[h];
	ihash[h] = x;
	nimport++;
	return x;
}
示例#4
0
static struct fn_decl *
lookup_std_proto (const char *name, int name_length)
{
    int i = hashstr (name, name_length) % HASH_SIZE;
    int i0 = i;
    for (;;)
    {
        struct fn_decl *fn;
        if (hash_tab[i] == 0)
            return NULL;
        fn = &std_protos[hash_tab[i]];
        if ((int) strlen (fn->fname) == name_length
                && strncmp (fn->fname, name, name_length) == 0)
            return fn;
        i = (i+1) % HASH_SIZE;
        gcc_assert (i != i0);
    }
}
示例#5
0
文件: go.c 项目: 29decibel/golang
static Pkg*
getpkg(char *path)
{
	Pkg *p;
	int h;
	
	h = hashstr(path) % nelem(phash);
	for(p=phash[h]; p; p=p->next)
		if(strcmp(p->path, path) == 0)
			return p;
	p = mal(sizeof *p);
	p->path = estrdup(path);
	p->next = phash[h];
	phash[h] = p;
	p->all = pkgall;
	pkgall = p;
	return p;
}
示例#6
0
char *LangPackTranslateString(const char *szEnglish, const int W)
{
	struct LangPackEntry key,*entry;

	if ( langPack.entryCount == 0 || szEnglish == NULL ) return (char*)szEnglish;

	key.englishHash = W ? hashstrW(szEnglish) : hashstr(szEnglish);
	entry=(struct LangPackEntry*)bsearch(&key,langPack.entry,langPack.entryCount,sizeof(struct LangPackEntry),(int(*)(const void*,const void*))SortLangPackHashesProc2);
	if(entry==NULL) return (char*)szEnglish;
	while(entry>langPack.entry)
	{
		entry--;
		if(entry->englishHash!=key.englishHash) {
			entry++;
			return W ? (char *)entry->wlocal : entry->local;
		}
	}
	return W ? (char *)entry->wlocal : entry->local;
}
示例#7
0
static HANDLE timeapiGetInfoByName(LPCTSTR tszName, DWORD dwFlags)
{
	if (tszName == NULL)
		return (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY)) ? NULL : &myInfo.myTZ;

	if (_tcscmp(myInfo.myTZ.tszName, tszName) == 0)
		return (dwFlags & TZF_DIFONLY) ? NULL : &myInfo.myTZ;

	MIM_TIMEZONE tzsearch;
	tzsearch.hash = hashstr(tszName);

	MIM_TIMEZONE *tz = g_timezones.find(&tzsearch);
	if (tz == NULL)
		return (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY)) ? NULL : &myInfo.myTZ;

	if (dwFlags & TZF_DIFONLY)
		return IsSameTime(tz) ? NULL : tz;

	return tz;
}
示例#8
0
Node *
new_SetNode(Node * obj, char *name, Node * expr)
{
   char *s;

   NEWVAR(ObjNode, ret);

   init_Node(ret, pass_SetNode, "set");
   ret->name = name;
   for (s = ret->name; *s; ++s)
      *s = toupper(*s);
   ret->hash = hashstr(name);
   ret->argc = 0;
   ret->obj = obj;
   append_Node(&ret->node, expr);
   curFunction->goto_trap_of_Function++;
   ins_name(name);

   return (Node *) ret;
}
示例#9
0
void *hm_get ( hashmap_t *hm, char *str )
{
    void *value;
    entry_t *e_ptr;
    int hashed = hashstr ( hm, str );

    if( hm->buckets[ hashed ] == NULL )
        return NULL;

    e_ptr = hm->buckets[ hashed ]->entries;
    
    while ( strcmp ( e_ptr->key, str ) != 0 )
    {
        if ( e_ptr->next != NULL )
            e_ptr = e_ptr->next;
        else
            return NULL;
    }

    return e_ptr->value;
}
示例#10
0
static clip_hash_t
n_hashstr(char *str)
{
   char *s;

   int is_dig = 1;

   for (s = str; *s; s++)
   {
      if (!isdigit(*s))
      {
	 is_dig = 0;
	 break;
      }
   }

   if (is_dig)
      return (clip_hash_t) atol(str);
   else
      return hashstr(str);
}
示例#11
0
Node *
newList_CallNode(char *name, Node * exprlist)
{
   char *s;

   NEWVAR(CallNode, ret);

   init_Node(ret, pass_CallNode, "call");
   join_Node((Node *) ret, exprlist);
   ret->name = name;
   for (s = ret->name; *s; ++s)
      *s = toupper(*s);
   ret->hash = hashstr(name);
   ret->argc = getCount_Node((Node *) ret);
   ret->isC = 1;
   ret->cfunc = curFunction;
   ins_name(name);
   curFunction->goto_trap_of_Function++;

   gettext_CallNode(ret);
   return (Node *) ret;
}
示例#12
0
static int
pass_CallNode(void *self, Pass pass, int level, void *par)
{
   VAR(CallNode, np, self);
   switch (pass)
   {
   case Print:
      fprintfOffs(stdout, level, "CallNode: %s (%d) byref=%d, isC=%d, rest=%d\n", np->name, np->argc, np->byref, np->isC, np->rest);
      break;
   case PrintSrc:
      {
	 VAR(CodestrNode, cp, par);
	 VAR(StrBuf, out, cp->buf);
	 VAR(Node, npp, self);
	 int r, n = 0;

	 putString_StrBuf(out, np->name);
	 putString_StrBuf(out, "(");
	 for (r = first_List(&npp->list); r; r = next_List(&npp->list))
	 {
		 VAR(Node, p, npp->list.current_of_List);
	    if (n)
	       putString_StrBuf(out, ", ");
	    n++;
	    if (p->pass(p, pass, level + 1, par))
	       break;
	 }
	 putString_StrBuf(out, ")");
      }
      return 0;
   case Codegen1:
      {
	 Node *npp = (Node *) np;

	 int r;

	 for (r = first_List(&npp->list); r; r = next_List(&npp->list))
	 {
		 VAR(Node, p, npp->list.current_of_List);
	    if (!strcmp(p->name, "ref"))
	    {
	       Node *np1 = ((RefNode *) p)->expr;

	       if (np1 && !strcmp(np1->name, "fmemvar"))
	       {
		  ((VarNode *) np1)->isArg = 1;
	       }
	    }
	 }
      }
      break;
   case CalcDeep:
      {
	 VAR(Function, fp, par);
	 int deep, ret;

	 np->isC = add_to_undeclared(np->name, &np->func);
	 addDeep(fp, 1);
	 deep = fp->deep_of_Function;
	 ret = pass_Node(self, pass, level, par);
	 fp->deep_of_Function = deep;
	 if (np->func && !np->func->isPublic_of_Function)
	    np->name = np->func->name_of_Function;
	 return ret;
      }
      break;
   case CText:
      {
	 VAR(FILE, out, par);
	 fprintfOffs(out, level, "_clip_push_nil( _mp );\n");
	 pass_Node(self, pass, level - 1, par);
	 switch (np->isC)
	 {
	 case 2:
	    fprintfOffs(out, level, "if ( (_ret=_clip_%s(_mp, clip_%s, %d, %d, %s))) goto _trap_%d;\n", np->node.isTop ? "proc" : "func", np->name, np->argc, np->rest, ref_name(np), np->node.seqNo);
	    break;
	 case 1:
	 case 0:
	    fprintfOffs(out, level,
			"if ( (_ret=_clip_%s_hash(_mp, %ld /* %s */, %d, %d, %s))) goto _trap_%d;\n",
			np->node.isTop ? "proc" : "func", (long) hashstr(np->name), np->name, np->argc, np->rest, ref_name(np), np->node.seqNo);
	    break;
	 }
	 return 0;
      }
      break;
   case OText:
      {
	 VAR(StrBuf, out, par);
	 putByte_StrBuf(out, CLIP_PUSH_NIL);
	 pass_Node(self, pass, level - 1, par);
	 switch (np->isC)
	 {
	 case 2:
	    if (np->node.isTop)
	       putByte_StrBuf(out, np->rest ? CLIP_SPROCR : CLIP_SPROC);
	    else
	       putByte_StrBuf(out, np->rest ? CLIP_SFUNCR : CLIP_SFUNC);
	    putByte_StrBuf(out, np->argc);
	    putShort_StrBuf(out, np->func->mno_of_Function);
	    break;
	 case 1:
	 case 0:
	    if (np->node.isTop)
	       putByte_StrBuf(out, np->rest ? CLIP_PROCR : CLIP_PROC);
	    else
	       putByte_StrBuf(out, np->rest ? CLIP_FUNCR : CLIP_FUNC);
	    putByte_StrBuf(out, np->argc);
	    putLong_StrBuf(out, hashstr(np->name));
	    break;
	 }
	 return 0;
      }
      break;
   case Traverse:
      {
	 VAR(TraversePar, tp, par);
	 tp->func((Node *) self, tp->par);
      }
      break;
   default:
      break;
   }

   return pass_Node(self, pass, level, par);
}
示例#13
0
static int LoadLangPack(const TCHAR *szLangPack)
{
	FILE *fp;
	char line[4096] = "";
	char *pszColon;
	char *pszLine;
	int entriesAlloced;
	int startOfLine=0;
	unsigned int linePos=1;
	LCID langID;
	UINT fileCp = CP_ACP;

	lstrcpy(langPack.filename,szLangPack);
	fp = _tfopen(szLangPack,_T("rt"));
	if(fp==NULL) return 1;
	fgets(line,SIZEOF(line),fp);
	size_t lineLen = strlen(line);
	if (lineLen >= 3 && line[0]=='\xef' && line[1]=='\xbb' && line[2]=='\xbf')
	{
		fileCp = CP_UTF8;
		memmove(line, line + 3, lineLen - 2);
	}
	lrtrim(line);
	if(lstrcmpA(line,"Miranda Language Pack Version 1")) {fclose(fp); return 2;}
	//headers
	while(!feof(fp)) {
		startOfLine=ftell(fp);
		if(fgets(line,SIZEOF(line),fp)==NULL) break;
		lrtrim(line);
		if(IsEmpty(line) || line[0]==';' || line[0]==0) continue;
		if(line[0]=='[') break;
		pszColon=strchr(line,':');
		if(pszColon==NULL) {fclose(fp); return 3;}
		*pszColon++ = 0;
		if(!lstrcmpA(line,"Language")) {mir_snprintf(langPack.language,sizeof(langPack.language),"%s",pszColon); lrtrim(langPack.language);}
		else if(!lstrcmpA(line,"Last-Modified-Using")) {mir_snprintf(langPack.lastModifiedUsing,sizeof(langPack.lastModifiedUsing),"%s",pszColon); lrtrim(langPack.lastModifiedUsing);}
		else if(!lstrcmpA(line,"Authors")) {mir_snprintf(langPack.authors,sizeof(langPack.authors),"%s",pszColon); lrtrim(langPack.authors);}
		else if(!lstrcmpA(line,"Author-email")) {mir_snprintf(langPack.authorEmail,sizeof(langPack.authorEmail),"%s",pszColon); lrtrim(langPack.authorEmail);}
		else if(!lstrcmpA(line, "Locale")) {
			char szBuf[20], *stopped;

			lrtrim(pszColon + 1);
			langID = (USHORT)strtol(pszColon, &stopped, 16);
			langPack.localeID = MAKELCID(langID, 0);
			GetLocaleInfoA(langPack.localeID, LOCALE_IDEFAULTANSICODEPAGE, szBuf, 10);
			szBuf[5] = 0;                       // codepages have max. 5 digits
			langPack.defaultANSICp = atoi(szBuf);
			if (fileCp == CP_ACP)
				fileCp = langPack.defaultANSICp;
		}
	}

	//body
	fseek(fp,startOfLine,SEEK_SET);
	entriesAlloced=0;
	while(!feof(fp)) {
		if(fgets(line,SIZEOF(line),fp)==NULL) break;
		if(IsEmpty(line) || line[0]==';' || line[0]==0) continue;
		rtrim(line);
		ConvertBackslashes(line, fileCp);
		if(line[0]=='[' && line[lstrlenA(line)-1]==']') {
			if(langPack.entryCount && langPack.entry[langPack.entryCount-1].local==NULL) {
				if(langPack.entry[langPack.entryCount-1].english!=NULL) mir_free(langPack.entry[langPack.entryCount-1].english);
				langPack.entryCount--;
			}
			pszLine = line+1;
			line[lstrlenA(line)-1]='\0';
			if(++langPack.entryCount>entriesAlloced) {
				entriesAlloced+=128;
				langPack.entry=(struct LangPackEntry*)mir_realloc(langPack.entry,sizeof(struct LangPackEntry)*entriesAlloced);
			}
			langPack.entry[langPack.entryCount-1].english=NULL;
			langPack.entry[langPack.entryCount-1].englishHash=hashstr(pszLine);
			langPack.entry[langPack.entryCount-1].local=NULL;
			langPack.entry[langPack.entryCount-1].wlocal = NULL;
			langPack.entry[langPack.entryCount-1].linePos=linePos++;
		}
		else if(langPack.entryCount) {
			struct LangPackEntry* E = &langPack.entry[langPack.entryCount-1];

			if(E->local==NULL) {
				E->local=mir_strdup(line);
				if (fileCp == CP_UTF8)
					Utf8DecodeCP(E->local, langPack.defaultANSICp, NULL);

				{
					int iNeeded = MultiByteToWideChar(fileCp, 0, line, -1, 0, 0);
					E->wlocal = (wchar_t *)mir_alloc((iNeeded+1) * sizeof(wchar_t));
					MultiByteToWideChar(fileCp, 0, line, -1, E->wlocal, iNeeded);
				}
			}
			else {
				size_t iOldLenA = strlen(E->local);
				E->local = (char*)mir_realloc(E->local, iOldLenA + strlen(line) + 2);
				strcat(E->local, "\n");
				strcat(E->local, line);
				if (fileCp == CP_UTF8)
					Utf8DecodeCP(E->local + iOldLenA + 1, langPack.defaultANSICp, NULL);
				{
					int iNeeded = MultiByteToWideChar(fileCp, 0, line, -1, 0, 0);
					size_t iOldLen = wcslen(E->wlocal);
					E->wlocal = (wchar_t*)mir_realloc(E->wlocal, ( sizeof(wchar_t) * ( iOldLen + iNeeded + 2)));
					wcscat(E->wlocal, L"\n");
					MultiByteToWideChar(fileCp, 0, line, -1, E->wlocal + iOldLen+1, iNeeded);
				}
			}
		}
	}

	fclose(fp);

	qsort(langPack.entry,langPack.entryCount,sizeof(LangPackEntry),(int(*)(const void*,const void*))SortLangPackHashesProc);
	return 0;
}
示例#14
0
文件: hints.c 项目: aahud/harvey
void
urlinit(void)
{
	static Biobuf *b = nil;
	static int64_t filelen = 0;
	int64_t newlen;
	char *s, *arena;
	int i, j, n;
	uint url;
	char *file;

	if(filelen < 0)
		return;
	file = "/sys/log/httpd/url";
	if(b == nil){
		b = Bopen(file, OREAD); /* first time */
		if(b == nil){
			syslog(0, HTTPLOG, "no %s, abandon prefetch hints", file);
			filelen = -1;
			return;
		}
	}
	newlen = Bfilelen(b); /* side effect: rewinds b */
	if(newlen == filelen || Bage(b)<300)
		return;
	filelen = newlen;
	if(filelen < 0)
		return;
	if(nurl){ /* free existing tables */
		free(urlname[0]); /* arena */
		memset(urlhash,0,sizeof urlhash);
		memset(urlnext,0,sizeof urlnext);
		nurl = 0;
	}
	if(urlname==nil)
		urlname = (char**)ezalloc(URLmax*sizeof(*urlname));
	arena = (char*)ezalloc(filelen);  /* enough for all the strcpy below */
	i = 1;
	while((s=Brdline(b,'\n'))!=0){
		/* read lines of the form:  999 /url/path */
		n = Blinelen(b) - 1;
		if(n>2 && s[n]=='\n'){
			s[n] = '\0';
		}else{
			sysfatal("missing fields or newline in url-db");
		}
		j = strtoul(s,&s,10);
		while(*s==' ')
			s++;
		if(i++!=j)
			sysfatal("url-db synchronization error");
		url = hashstr(s);
		j = urllookup(url);
		if(j>=0)
			sysfatal("duplicate url");
		j = -j;
		nurl++;
		if(nurl>=URLmax){
			syslog(0, HTTPLOG, "urlinit overflow at %s",s);
			free(urlname[0]); /* arena */
			memset(urlhash,0,sizeof urlhash);
			memset(urlnext,0,sizeof urlnext);
			nurl = 0;
			return;
		}
		urltab[nurl] = url;
		urlnext[nurl] = urlhash[j];
		urlhash[j] = nurl;
		strcpy(arena,s);
		urlname[nurl] = arena;
		arena += strlen(s)+1;
	}
	syslog(0, HTTPLOG, "prefetch-hints url=%d (%.1fMB)", nurl, 1.e-6*(URLmax*sizeof(*urlname)+filelen));
	/* b is held open, because namespace will be chopped */
}
static int
pass_AssignFmemvarNode(void *self, Pass pass, int level, void *par)
{
   VAR(AssignNode, np, self);
   switch (pass)
   {
   case Print:
      fprintfOffs(stdout, level, "AssignFmemvarNode:\n");
      break;
   case PrintSrc:
      {
	 VAR(CodestrNode, cp, par);
	 VAR(StrBuf, out, cp->buf);
	 putString_StrBuf(out, ((VarNode *) np->var)->vp->name);
	 putString_StrBuf(out, ":=");
	 np->expr->pass(np->expr, pass, level, par);
      }
      return 0;
   case CalcDeep:
      break;
   case CText:
      {
	 VAR(FILE, out, par);
	 VAR(VarNode, vp, np->var);

	 np->expr->pass(np->expr, pass, level, par);
	 if (np->node.isTop)
	 {
	    fprintfOffs(out, level, "if ((_ret=_clip_fm_assign( _mp, " "%ld /* %s */  ))) goto _trap_%d;\n", (long) hashstr(vp->vp->name), vp->vp->name, np->node.seqNo);
	 }
	 else
	 {
	    fprintfOffs(out, level, "if ((_ret=_clip_fm_iassign( _mp, " "%ld /* %s */  ))) goto _trap_%d;\n", (long) hashstr(vp->vp->name), vp->vp->name, np->node.seqNo);
	 }
      }
      return 0;
   case OText:
      {
	 VAR(StrBuf, out, par);
	 VAR(VarNode, vp, np->var);

	 np->expr->pass(np->expr, pass, level, par);
	 if (np->node.isTop)
	 {
	    putByte_StrBuf(out, CLIP_FM_ASSIGN);
	    putLong_StrBuf(out, hashstr(vp->vp->name));
	 }
	 else
	 {
	    putByte_StrBuf(out, CLIP_FM_IASSIGN);
	    putLong_StrBuf(out, hashstr(vp->vp->name));
	 }
      }
      return 0;
   case Traverse:
      {
	 VAR(TraversePar, tp, par);
	 tp->func((Node *) self, tp->par);
      }
      break;
   default:
      break;
   }
   np->var->pass(np->var, pass, level + 1, par);
   np->expr->pass(np->expr, pass, level + 1, par);
   return 0;
}
示例#16
0
文件: var.cpp 项目: NotFound/Blassic
	size_t operator () (const std::string & str) const
	{ return hashstr (str.c_str () ); }
示例#17
0
//before we load the index , do memory usage check
//if run out of memory limitation, release
void do_weed(idx_map_t *idx, trans_info_t *trans_log, const string &f)
{

        uint64_t fc = 0;
        uint64_t ec = 0;

        string fname = config::conf_inputdir + "/" + f;

        string tmpname = config::conf_tmpdir + "/" + f + ".chk";

        char tbs[16];
        full_time_str(tbs, time(0));

        //for memory mangment
        if (!mm_factor) {

                size_t total_node = atol(config::conf_maxmem.c_str());
                total_node *= max_mem_unit;
                total_node /= key_max *atol(config::conf_records_per_node.c_str() ) ;

                mm_factor =atol(config::conf_records_per_node.c_str() )  / total_node;

                mylog->write("runtime mm_factor:%llu\n", (int64_t)mm_factor);
#ifdef DEBUG_PRINT_L3

#endif
        }
        if (mm_factor== 0) {
                mm_factor = 1;
        }

        FILE *fpin = fopen(fname.c_str(), "r");
        if (!fpin) {
                string msg= "can not open:" + fname;
                msg += ":";
                msg += strerror(errno);
                throw runtime_error(msg);
        }

        FILE *fptmp = fopen(tmpname.c_str(), "w");
        if (!fptmp) {
                string msg= "can not open:" + tmpname;
                msg += ":";
                msg += strerror(errno);
                throw runtime_error(msg);
        }


        uint64_t records_per_node = atoi(config::conf_records_per_node.c_str() );
        uint64_t max_mem = atol(config::conf_maxmem.c_str()) ;
        max_mem *= max_mem_unit;

        char dup_key[key_max];
        find_visitor<char> fv(dup_key, mem_layout);

        string prev_file_idx;
        fcache_map_t :: iterator prev_trans_itr;
        idx_map_t::iterator prev_idx_itr;

        uint64_t sync_count = 0;
        vector <string> verr ;
        string cur_file_idx;
        char line_buf[line_max+1];
        while (fgets(line_buf, line_max + 1, fpin)) {
                string cur_file_idx;
                fcache_map_t :: iterator cur_trans_itr;
                idx_map_t::iterator cur_idx_itr;

                //make the file index
                mk_file_idx(&cur_file_idx, line_buf);
                //make the duplicate key for record
                mk_dup_key(dup_key, line_buf);

                //do previous cache check
                if (cur_file_idx == prev_file_idx) {
                        cur_trans_itr = prev_trans_itr;
                        cur_idx_itr = prev_idx_itr;
                } else {//no cache node found , we need a new node
                        cur_idx_itr = idx->find(cur_file_idx);

                        cur_trans_itr = trans_log->idx_map.find(cur_file_idx);
                        if (cur_trans_itr == trans_log->idx_map.end()) {
                        	file_cache_t fc;
                                cur_trans_itr = trans_log->idx_map.insert(
                                		fcache_map_t::value_type(cur_file_idx, fc)
                                                ).first;
                        }

                        if (cur_idx_itr == idx->end()) {//this file index does not resident in memory
                                mem_adjust(idx, max_mem); //do the MM( memory management)

                                if(
                                		  (fc-ec-sync_count)  * 100 * mem_layout[0].len  > max_mem* cache_max_percent
                                		 ){
                                	cache_write(config::conf_tmpdir,  & trans_log->idx_map);
                               	mylog->write("cache_write:on records: %llu, mem:%llu,maxmem,%llu\n",
                                			fc-ec-sync_count, (fc-ec-sync_count) *mem_layout[0].len, max_mem);
                               	sync_count += fc-ec-sync_count;

                                }
                                data_node_t dn;
                                dn.count = records_per_node;
                                dn.data = new htable<char>(records_per_node,
                                                           vector <int>(1, 0));
                                dn.data->set_layout(mem_layout);
                                cur_idx_itr = idx->insert(idx_map_t::value_type(cur_file_idx, dn)).first;

                                //check if it exist in the disk file
                                string idx_disk_file = config::conf_idxdir + "/" + cur_file_idx;
                                if (access(idx_disk_file.c_str(), F_OK) == 0) { // the index resident in the disk
                                        load_idx(cur_idx_itr->second.data, idx_disk_file);
                                }

                                // note , if we get a new index node,  there may be the node out of synchronize
                                //load it to memory too
                                if (cur_trans_itr->second.cache.size()) {
                                        vector<string>::const_iterator vitr = cur_trans_itr->second.cache.begin();
                                        while (vitr !=  cur_trans_itr->second.cache.end()) {
                                                char vec_buf[key_max];
                                                vitr->copy(vec_buf, key_max);
                                                cur_idx_itr->second.data->insert(hnode<char>(vec_buf));
                                                ++vitr;
                                        }

                                }
                                if(cur_trans_itr->second.file.length()){
                                	load_idx(  cur_idx_itr->second.data, cur_trans_itr->second.file);
                                }

                        }


                        //update the cache node
                        prev_trans_itr = cur_trans_itr;
                        prev_idx_itr = cur_idx_itr;
                        prev_file_idx = cur_file_idx;
                }

                //do the duplicate check
                fv.reset();
                size_t hpos = hashstr(dup_key)%cur_idx_itr->second.data->size();
                cur_idx_itr->second.data->at(hpos).accept(fv);
                ++ cur_idx_itr->second.count;


                ++fc;
                if (!fv.done()) {
                        cur_idx_itr->second.data->insert(hpos, hnode<char>(dup_key));
                        cur_trans_itr->second.cache.push_back(dup_key);
                        fputs(line_buf, fptmp);
                } else { //duplicate record
                        string es = EDUP;
                        es += line_buf;
                        verr.push_back(es);
                        ++ec;
                }

        }

        fclose(fptmp);
        fclose(fpin);


        //record the transaction file :

        map<string, file_cache_t >:: const_iterator citr ;
        for (citr = trans_log->idx_map.begin(); citr != trans_log->idx_map.end(); ++citr) {
		string fname = config::conf_idxdir + "/" + citr -> first;
		unsigned long long flen = 0;
		if (access(fname.c_str(), F_OK) == 0) { //not exist in the disk
			flen = file_size(fname);
		}
		char buf[64];
		sprintf(buf, "%llu", (uint64_t) flen);
		string trun_cmd = truncate_cmd + cmd_separator + fname + cmd_separator
				+ buf;
		trans_log->trans_cmd.push_back(trun_cmd);
		if (citr->second.file.length()) {// there is some index data synchronize to disk, remove it
			string rmtmp = rm_cmd;
			rmtmp += cmd_separator;
			rmtmp += citr->second.file;
			trans_log->trans_cmd.push_back(rmtmp);
		}
	}

        string fcmd;
        if (config::conf_is_backup == "yes") {
                fcmd= mv_cmd + cmd_separator + fname + cmd_separator + config::conf_bakdir + "/" +f;
                trans_log->trans_cmd.push_back(fcmd);
        }

        if (verr.size()) {
                string errname = config::conf_tmpdir + "/" + f + ".dup";
                vwrite(errname, verr);
                fcmd= mv_cmd + cmd_separator + errname + cmd_separator + config::conf_errdir + "/" + f;
                size_t fl = fcmd.length();

                fcmd.replace(fl - 4, 4, ".dup");
                trans_log->trans_cmd.push_back(fcmd);
        }


        if (file_size(tmpname)) {
                fcmd= mv_cmd + cmd_separator + tmpname + cmd_separator + config::conf_outdir + "/" + f;
                size_t fl = fcmd.length();
                string::size_type dot = f.rfind('.');
                                if(dot == string::npos){
                                	fcmd += ".chk";
                                }else
                                	if(dot ==  (fl -4) ){
                                		fcmd.replace(fl - 4, 4, ".chk");

                                }else{
                                	fcmd += ".chk";
                                }


                trans_log->trans_cmd.push_back(fcmd);
        } else {
                fcmd= rm_cmd + cmd_separator + tmpname;
                trans_log->trans_cmd.push_back(fcmd);

        }



        char tbe[16];
        full_time_str(tbe, time(0));
        mylog->write("%s,%s,%llu,%llu,%llu,%llu,%llu,%s,%s,%s\n"
                     , "ProcInfo"
                     , f.c_str()
                     , (uint64_t)fc
                     , (uint64_t)(fc - ec)
                     , (uint64_t)ec
                     , (uint64_t) 0
                     , (uint64_t) file_size(fname)
                     , tbs
                     , tbe
                     , config::conf_inputdir.c_str()
                    );

}
示例#18
0
void InitTimeZones(void)
{
	REG_TZI_FORMAT	tzi;
	HKEY			hKey;

	const TCHAR *tszKey = IsWinVerNT() ?
		_T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones") :
		_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Time Zones");

	/*
	 * use GetDynamicTimeZoneInformation() on Vista+ - this will return a structure with
	 * the registry key name, so finding our own time zone later will be MUCH easier for
	 * localized systems or systems with a MUI pack installed
	 */
	if (IsWinVerVistaPlus()) 
		pfnGetDynamicTimeZoneInformation = (pfnGetDynamicTimeZoneInformation_t)GetProcAddress(GetModuleHandle(_T("kernel32")), "GetDynamicTimeZoneInformation");

	if (IsWinVer2000Plus())
	{
		pfnSHLoadIndirectString = (pfnSHLoadIndirectString_t)GetProcAddress(GetModuleHandle(_T("shlwapi")), "SHLoadIndirectString");
		pfnGetSystemDefaultUILanguage = (pfnGetSystemDefaultUILanguage_t)GetProcAddress(GetModuleHandle(_T("kernel32")), "GetSystemDefaultUILanguage");
		pfnGetUserDefaultUILanguage = (pfnGetUserDefaultUILanguage_t)GetProcAddress(GetModuleHandle(_T("kernel32")), "GetUserDefaultUILanguage");
		muiInstalled = pfnSHLoadIndirectString && pfnGetSystemDefaultUILanguage() != pfnGetUserDefaultUILanguage();
	}

	pfnSendMessageW = (pfnSendMessageW_t)GetProcAddress(GetModuleHandle(_T("user32")), "SendMessageW");

	if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, tszKey, 0, KEY_ENUMERATE_SUB_KEYS, &hKey)) 
	{
		DWORD	dwIndex = 0;
		HKEY	hSubKey;
		TCHAR	tszName[MIM_TZ_NAMELEN];

		DWORD dwSize = SIZEOF(tszName);
		while (ERROR_NO_MORE_ITEMS != RegEnumKeyEx(hKey, dwIndex++, tszName, &dwSize, NULL, NULL, 0, NULL))
		{
			if (ERROR_SUCCESS == RegOpenKeyEx(hKey, tszName, 0, KEY_QUERY_VALUE, &hSubKey)) 
			{
				dwSize = sizeof(tszName);

				DWORD dwLength = sizeof(tzi);
				if (ERROR_SUCCESS != RegQueryValueEx(hSubKey, _T("TZI"), NULL, NULL, (unsigned char *)&tzi, &dwLength)) 
					continue;

				MIM_TIMEZONE *tz = new MIM_TIMEZONE;

				tz->tzi.Bias = tzi.Bias;
				tz->tzi.StandardDate = tzi.StandardDate;
				tz->tzi.StandardBias = tzi.StandardBias;
				tz->tzi.DaylightDate = tzi.DaylightDate;
				tz->tzi.DaylightBias = tzi.DaylightBias;

				_tcscpy(tz->tszName, tszName);
				tz->hash = hashstr(tszName);
				tz->offset = INT_MIN;

				GetLocalizedString(hSubKey, _T("Display"), tz->szDisplay, SIZEOF(tz->szDisplay));
				GetLocalizedString(hSubKey, _T("Std"), tz->tzi.StandardName, SIZEOF(tz->tzi.StandardName));
				GetLocalizedString(hSubKey, _T("Dlt"), tz->tzi.DaylightName, SIZEOF(tz->tzi.DaylightName));

				g_timezones.insert(tz);
				g_timezonesBias.insert(tz);

				RegCloseKey(hSubKey);
			}
			dwSize = SIZEOF(tszName);
		}
		RegCloseKey(hKey);
	}

	RecalculateTime();

	CreateServiceFunction(MS_SYSTEM_GET_TMI, GetTimeApi);

	CreateServiceFunction(MS_DB_TIME_TIMESTAMPTOLOCAL, TimestampToLocal);
	CreateServiceFunction(MS_DB_TIME_TIMESTAMPTOSTRINGT, TimestampToStringT);
#ifdef _UNICODE
	CreateServiceFunction(MS_DB_TIME_TIMESTAMPTOSTRING, TimestampToStringA);
#else
	CreateServiceFunction(MS_DB_TIME_TIMESTAMPTOSTRING, TimestampToStringT);
#endif


	tmi.cbSize = sizeof(tmi);
	GetTimeApi(0, (LPARAM)&tmi);
}
示例#19
0
static void
write_Function(FILE * out, File * file, Function * fp)
{
   int j;

   int namelen;

   int local_locals = 0;

   clic_line = fp->line_of_Function;
   if (file->Function_init_of_File != fp)
      fprintf(out, "\n%sint\nclip_%s(ClipMachine *_mp)\n{\n", fp->isPublic_of_Function ? "" : "static ", fp != file->Function_init_of_File ? fp->name_of_Function : "_init");
   else
      fprintf(out, "\nstatic int\n_init(ClipMachine *_mp, ClipFrame *_frame_p)\n{\n");

   fprintf(out, "\tint _ret = 0;\n");
   if (fp->haveIf_of_Function)
      fprintf(out, "\tint _if;\n");
   fprintf(out, "\tClipVar _stack [ %d ];\n", fp->maxdeep_of_Function + 1);

#if 0
   if (fp->reflocals)
   {
      fprintf(out, "\tClipVar _reflocals [ %d ];\n", fp->reflocals);
   }
#else
   for (namelen = 1, j = 0; j < fp->VarColl_locals_of_Function->unsorted.count_of_Coll; j++)
   {
		VAR(Var, vp, fp->VarColl_locals_of_Function->unsorted.items_of_Coll[j]);
      namelen += strlen(vp->name) + 1;
   }

   if (!fp->nlocals_of_Function && !fp->reflocals_of_Function)
   {
      fprintf(out, "\tClipVarFrame *_localvars = _mp->fp->ClipVarFrame_localvars_of_ClipFrame;\n");
   }
   else if (fp->reflocals_of_Function)
   {
      int i, l;

		fprintf(out, "\tClipVarFrame *_localvars = (ClipVarFrame*) calloc(1, sizeof(ClipVarFrame)+%d*sizeof(ClipVar));\n", fp->VarColl_locals_of_Function->unsorted.count_of_Coll);
      fprintf(out, "\tstatic const char _localnames[] = {");
		for (j = 0; j < fp->VarColl_locals_of_Function->unsorted.count_of_Coll; j++)
      {
			VAR(Var, vp, fp->VarColl_locals_of_Function->unsorted.items_of_Coll[j]);
	 if (vp->isRef)
	    continue;
	 l = strlen(vp->name);
	 for (i = 0; i <= l; i++)
	    fprintf(out, "%d, ", vp->name[i]);
	 fprintf(out, " /* %s */ ", vp->name);
      }
            for (j = 0; j < fp->VarColl_locals_of_Function->unsorted.count_of_Coll; j++)
      {
			VAR(Var, vp, fp->VarColl_locals_of_Function->unsorted.items_of_Coll[j]);
	 if (!vp->isRef)
	    continue;
	 l = strlen(vp->name);
	 for (i = 0; i <= l; i++)
	    fprintf(out, "%d, ", vp->name[i]);
	 fprintf(out, " /* %s */ ", vp->name);
      }
      fprintf(out, "0 };\n");
   }
   else
   {
		int numlocals = fp->VarColl_locals_of_Function->unsorted.count_of_Coll;

      int i, l;

      local_locals = 1;
      fprintf(out, "\tClipVar _vlocals [ %d ] = { ", numlocals);
      for (j = 0; j < numlocals - 1; j++)
	 fprintf(out, "{ {UNDEF_type_of_ClipVarType, 0,0,0,0} }, ");
      if (numlocals)
	 fprintf(out, "{ {UNDEF_type_of_ClipVarType, 0,0,0,0} } ");
      fprintf(out, "};\n");
      fprintf(out, "\tconst char _localnames[] = { ");
		for (j = 0; j < fp->VarColl_locals_of_Function->unsorted.count_of_Coll; j++)
      {
			VAR(Var, vp, fp->VarColl_locals_of_Function->unsorted.items_of_Coll[j]);
	 if (vp->isRef)
	    continue;
	 l = strlen(vp->name);
	 for (i = 0; i <= l; i++)
	    fprintf(out, "%d, ", vp->name[i]);
	 fprintf(out, " /* %s */ ", vp->name);
      }
            for (j = 0; j < fp->VarColl_locals_of_Function->unsorted.count_of_Coll; j++)
      {
			VAR(Var, vp, fp->VarColl_locals_of_Function->unsorted.items_of_Coll[j]);
	 if (!vp->isRef)
	    continue;
	 l = strlen(vp->name);
	 for (i = 0; i <= l; i++)
	    fprintf(out, "%d, ", vp->name[i]);
	 fprintf(out, " /* %s */ ", vp->name);
      }
      fprintf(out, "0 };\n");
		fprintf(out, "\tClipVarFrame _local_vars = { 0, %d, _vlocals, _localnames }, *_localvars = &_local_vars;\n", fp->VarColl_locals_of_Function->unsorted.count_of_Coll);
   }
#endif

#if 0
   for (j = 0; j < fp->VarColl_locals_of_Function->unsorted.count; j++)
   {
      VAR(Var, vp, fp->VarColl_locals_of_Function->unsorted.items[j]);
      if (vp->isRef)
	 continue;
      if (!vp->init)
	 fprintf(out, "\tClipVar %s = { {UNDEF_type_of_ClipVarType, 0, 0,0,0} };\n", vp->name);
      else if (vp->init->isConst && !vp->init->isArray)
      {
	 if (vp->init->isNum)
	    fprintf(out, "\tClipVarNum %s = ", vp->name);
	 else if (vp->init->isStr)
	    fprintf(out, "\tClipVarStr %s = ", vp->name);
	 else if (vp->init->isLog)
	    fprintf(out, "\tClipVarLog %s = ", vp->name);
	 else if (vp->init->isCode)
	    fprintf(out, "\tClipVarCode %s = ", vp->name);
	 else
	    fprintf(out, "\tClipVar %s = ", vp->name);
	 vp->init->pass(vp->init, CTextInit, 0, out);
	 fprintf(out, ";\n");
      }
      else
	 fprintf(out, "\tClipVar %s = { {UNDEF_type_of_ClipVarType, 0, 0,0,0} };\n", vp->name);
   }
#endif
   /*
      if (fp->VarColl_params_of_Function->coll.count)
      {
      int i, c=fp->VarColl_params_of_Function->coll.count;

      fprintf(out, "\tClipVar _params[%d] = { ", c);
      for(i=0; i<c; ++i)
      fprintf(out, "{ UNDEF_type_of_ClipVarType, 0, 0,0,0 },");
      fprintf(out, " };\n");
      }
    */

#if 0
   {
      fprintf(out, "\tClipVarDef _locals[] =\n\t{\n");
      fprintf(out, "\t\t{ %d, 0 },\n", fp->VarColl_locals_of_Function->coll.count);
      for (j = 0; j < fp->VarColl_locals_of_Function->coll.count; j++)
      {
	 VAR(Var, vp, fp->VarColl_locals_of_Function->coll.items[j]);
	 if (vp->isRef)
	    fprintf(out, "\t\t{ %ld, _reflocals+%d },\n", (long) hashstr(vp->name), -vp->no);
	 else
	    fprintf(out, "\t\t{ %ld, &%s },\n", (long) hashstr(vp->name), vp->name);
      }
      fprintf(out, "\t};\n");
   }
#else
#endif

   fprintf(out,
	   "\tClipFrame _frame = { _stack, _stack, _file, %d, 0, %s, 0, _statics, 0, &_hash_names,\"%s\", %d, 0 };\n",
	   fp->line_of_Function, "_localvars", fp->isPublic_of_Function ? fp->name_of_Function : fp->name_of_Function + 3, fp->maxdeep_of_Function + 1);

   if (file->Function_init_of_File != fp && !fp->nlocals_of_Function && !fp->reflocals_of_Function)
   {
      fprintf(out, "\tif (_localvars && _localvars->refcount_of_ClipVarFrame)\n\t\t_localvars->refcount_of_ClipVarFrame++;\n");
   }
   else if (fp->reflocals_of_Function)
   {
      fprintf(out, "\t_localvars->ClipVar_vars_of_ClipVarFrame = (ClipVar*) (_localvars + 1);\n");
      fprintf(out, "\t_localvars->refcount_of_ClipVarFrame = 1;\n");
      fprintf(out, "\t_localvars->size_of_ClipVarFrame = %d;\n", fp->nlocals_of_Function + fp->reflocals_of_Function);
      fprintf(out, "\t_localvars->names_of_ClipVarFrame = _localnames;\n");
   }

   if (file->Function_init_of_File != fp)
   {
      fprintf(out, "\t_init( _mp, &_frame );\n");
      fprintf(out, "\t_clip_log_call( _mp );\n\n");
   }
   else
   {
      fprintf(out, "\t_frame_p->ClipFrame_up_of_ClipFrame = _mp->fp;\n");
      fprintf(out, "\tif (_init_flag)\n\t{\n");
      fprintf(out, "\t\t_mp->fp = _frame_p;\n");
      fprintf(out, "\t\treturn 0;\n\t}\n");
      fprintf(out, "\telse if (_localvars && _localvars->refcount_of_ClipVarFrame)\n\t\t_localvars->refcount_of_ClipVarFrame++;\n");
      fprintf(out, "\t_frame.ClipFrame_up_of_ClipFrame = _mp->fp;\n");
      fprintf(out, "\t_mp->fp = &_frame;\n");
      fprintf(out, "\t_init_flag = 1;\n");

      /*
         for(i=0;i<file->Coll_unsortedFunctions.count;i++)
         {
         VAR(Function, fp, file->Coll_unsortedFunctions_of_File.items[i]);
         if (fp->isPublic_of_Function)
         fprintf(out, "\t_clip_register( %s, \"%s\" );\n", fp->name_of_Function, fp->name_of_Function);
         }
       */
      fprintf(out, "\n");
   }

#if 0
   if (fp->reflocals)
      fprintf(out, "\t_clip_mptr(_mp, _reflocals, %d);\n", fp->reflocals_of_Function);
#endif

   pass_Node(fp->Node_body_of_Function, CText, 0, out);

   if (file->Function_init_of_File == fp)
      file->Node_ctextStatic_of_File->pass(file->Node_ctextStatic_of_File, CText, 0, out);

   if ( /*file->Function_init_of_File !=fp && */ fp->goto_trap_of_Function)
   {
      fprintf(out, "\n\tgoto _return;\n");
      fprintf(out, "_trap_0:\n");
      /*fprintf(out, "\t_ret = 1;\n"); */
      fprintf(out, "\t_clip_trap(_mp, _file, _frame.line_of_ClipFrame);\n");
   }

   fprintf(out, "_return:\n");
#if 1
   if (local_locals)
      fprintf(out, "\t_clip_destroy_locals( _mp );\n");
   fprintf(out, "\t_clip_resume( _mp, %d, %d );\n", fp->nlocals_of_Function, fp->reflocals_of_Function);
#else
   fprintf(out, "\t_clip_resume( _mp, %d ", fp->nlocals_of_Function);
   if (fp->nlocals_of_Function)
   {
      for (j = fp->VarColl_locals_of_Function->unsorted.count - 1; j >= 0; --j)
      {
	 VAR(Var, vp, fp->VarColl_locals_of_Function->unsorted.items[j]);
	 if (vp->isRef)
	    continue;
	 fprintf(out, ", &%s", vp->name);
      }
   }
   fprintf(out, " );\n");
#if 0
   if (fp->reflocals)
   {
      fprintf(out, "\t_clip_vresume(_mp, %d, _reflocals);\n", fp->reflocals_of_Function);
   }
#endif
#endif
   /*
      if (fp->VarColl_params_of_Function->coll.count)
      {
      int c=fp->VarColl_params_of_Function->coll.count;
      fprintf(out, "\t_clip_vresume(_mp, %d, _params);\n", c);
      }
    */

#if 0
   if ((fp->VarColl_privates_of_Function->unsorted.count + fp->VarColl_parameters_of_Function->unsorted.count) > 0)
   {
      fprintf(out, "\t_clip_remove_privates( _mp, %d", fp->VarColl_privates_of_Function->unsorted.count + fp->VarColl_parameters_of_Function->unsorted.count);
      for (j = fp->VarColl_privates_of_Function->unsorted.count - 1; j >= 0; --j)
      {
	 VAR(Var, vp, fp->VarColl_privates_of_Function->unsorted.items[j]);
	 fprintf(out, ", %ld", (long) hashstr(vp->name));
      }
      for (j = fp->VarColl_parameters_of_Function->unsorted.count - 1; j >= 0; --j)
      {
	 VAR(Var, vp, fp->VarColl_parameters_of_Function->unsorted.items[j]);
	 fprintf(out, ", %ld", (long) hashstr(vp->name));
      }
      fprintf(out, ");\n");
   }
#endif

   if (file->Function_init_of_File == fp)
   {
      /*fprintf(out, "\t_frame_p->up = _mp->fp;\n"); */
      fprintf(out, "\t_mp->fp = _frame_p;\n");
   }
   fprintf(out, "\treturn _ret;\n}\n");
}
示例#20
0
void
write_Cfunc(const char *name, int argc, char **argv, Coll * ex, Coll * nm)
{
   char buf[1024 * 8];

   char word1[80], word2[80], word3[80];

   int i, use_asm = 0, count;

   FILE *in = 0, *out = 0;

   int shared = shared_flag || eshared_flag;

   time_t tbuf;

   Coll names;

   Coll fnames;

   Coll dnames;

   Coll rnames;

   Coll objs;

   Coll libs;

   Coll nlibs, slibs;

   Coll alibs;

   int labn, labcn;

   init_Coll(&names, free, strcmp);
   init_Coll(&fnames, free, 0 /*strcmp */ );
   init_Coll(&dnames, free, strcmp);
   init_Coll(&rnames, free, strcmp);
   init_Coll(&objs, free, 0);
   init_Coll(&libs, free, 0);
   init_Coll(&nlibs, free, 0);
   init_Coll(&slibs, 0, strcmp);
   init_Coll(&alibs, 0, 0);

   strcpy(buf, NM_PRG);

   for (i = 0; i < argc; i++)
   {
      char *a = argv[i];

      if (a[0] == '-' && a[1] == 'l')
      {
	 char path[256];

	 snprintf(path, sizeof(path), "%s/lib/lib%s%s", CLIPROOT, a + 2, SLIBSUF);
	 if (!access(path, R_OK))
	    append_Coll(&libs, strdup(path));

	 continue;
      }
      if (a[0] == '-')
      {
	 continue;
      }
      if (strsuff(a, SLIBSUF) || strsuff(a, LIBSUF))
      {
	 if (a[0] == '/' || (a[0] == '.' && a[1] == '/') || (a[0] == '.' && a[1] == '.' && a[2] == '/'))
	 {
	    append_Coll(&libs, strdup(a));
	 }
	 else
	 {
	    char path[256];

	    snprintf(path, sizeof(path), "%s/lib/%s", CLIPROOT, a);
	    if (!access(path, R_OK))
	       append_Coll(&libs, strdup(path));
	 }
      }
      else if (strsuff(a, SOBJSUF) || strsuff(a, OBJSUF))
	 append_Coll(&objs, strdup(a));
   }

   for (i = libs.count_of_Coll - 1; i >= 0; i--)
   {
		char *s = (char *) libs.items_of_Coll[i];

      char *e, *r, *b;

      int l, j, ind, isA = 0;

      e = strsuff(s, SLIBSUF);

      if (!e)
      {
	 e = strsuff(s, LIBSUF);
	 isA = 1;
      }
      b = strrchr(s, '/');
      if (!b)
	 b = s;
      else
	 b++;
      if (e && e > b + 1)
	 l = e - b;
      else
	 l = strlen(b);
      r = (char *) malloc(l + 1);
      for (j = 0; j < l; j++)
      {
	 switch (b[j])
	 {
	 case '-':
	    r[j] = '_';
	    break;
	 default:
	    r[j] = b[j];
	    break;
	 }
      }
      r[l] = 0;
      if (!search_Coll(&slibs, s, &ind))
      {
	 insert_Coll(&slibs, r);
	 if (isA)
	 {
	    append_Coll(&alibs, s);
	    free(r);
	 }
	 else
	    append_Coll(&nlibs, r);
      }
      else
	 free(r);

      read_names(s, ex, nm);
   }

   if (!shared)
   {
		for (i = 0; i < libs.count_of_Coll; i++)
      {
			char *s = (char *) libs.items_of_Coll[i];

	 strcat(buf, " ");
	 strcat(buf, s);
      }
   }
   else
   {
		for (i = 0; i < alibs.count_of_Coll; i++)
      {
			char *s = (char *) alibs.items_of_Coll[i];

	 strcat(buf, " ");
	 strcat(buf, s);
      }
   }

   for (i = 0; i < objs.count_of_Coll; i++)
   {
		char *s = (char *) objs.items_of_Coll[i];

      strcat(buf, " ");
      strcat(buf, s);

      read_names(s, ex, nm);
   }

   v_printf(2, "%s\n", buf);

   in = popen(buf, "r");

   if (!in)
   {
      yyerror("cannot open pipe '%s'", buf);
      goto end;
   }

#ifdef USE_AS
   {
      char *s = strrchr(name, '.');

      if (asm_flag && s && !strcmp(s, ".s"))
	 use_asm = 1;
   }
#endif

   out = fopen(name, "wb");
   if (!out)
   {
      yyerror("cannot open output file '%s'", name);
      goto end;
   }

   fprintf(out, "/*\n");
   fprintf(out, " *\tautomatically generated by clip-");
   printVersion(out);
   fprintf(out, "\n");
   time(&tbuf);
   fprintf(out, " *\tat %s", ctime(&tbuf));
   fprintf(out, " *\tfrom sources:\n");
   for (i = 0; i < argc; ++i)
      fprintf(out, " *\t%s\n", argv[i]);
   fprintf(out, " */\n");

   if (!use_asm)
   {
      fprintf(out, "\n#include \"ci_clip.h\"\n");
   }
   else
   {
      fprintf(out, "\n\t.file \"%s\"\n", name);
   }

   while (fgets(buf, sizeof(buf), in) != NULL)
   {
      char *s, *sp;

      int br;

      int n = sscanf(buf, "%s %s %s", word1, word2, word3);

      int l;

      if (n == 3)
      {
	 if (!strcmp(word2, "T"))
	    br = 1;
	 else if (!strcmp(word2, "D"))
	    br = 2;
	 else
	    continue;
	 sp = word3;
      }
      else if (n == 2)
      {
	 if (strcmp(word1, "U"))
	    continue;
	 sp = word2;
	 br = 3;
      }
      else
	 continue;
#ifdef NM_UNDERSCORE
      sp++;
#endif
      l = strlen(sp);
      if (l < 6 || memcmp(sp, "clip_", 5))
	 goto next;

      for (s = sp + 5; *s; ++s)
	 if (!isupper(*s) && !isdigit(*s) && *s != '_')
	    goto next;
      if (br == 2)
      {
	 if (!memcmp(sp + 5, "_PCODE_", 7))
	    insert_Coll(&fnames, strdup(sp));
	 else if (!memcmp(sp + 5, "_RDD_", 4))
	    insert_Coll(&dnames, strdup(sp));
	 else if (!memcmp(sp + 5, "_RTTI_", 6))
	    insert_Coll(&rnames, strdup(sp));
      }
      else
	 insert_Coll(&names, strdup(sp));
    next:
      ;
   }
   if (in)
   {
      pclose(in);
      in = 0;
   }

   for (i = 0; i < names.count_of_Coll; ++i)
   {
		VAR(char, s, names.items_of_Coll[i]);

      if (!use_asm)
	 fprintf(out, "ClipFunction %s;\n", s);
      add_name(nm, s);
   }

   if (shared)
   {
		for (i = nlibs.count_of_Coll - 1; i >= 0; i--)
      {
			char *s = (char *) nlibs.items_of_Coll[i];

	 if (!use_asm)
	    fprintf(out, "CLIP_DLLIMPORT ClipFunction *_clip_builtin_%s ( long hash );\n", s);
      }
   }

   labn = 3;
   labcn = 0;
   if (!use_asm)
   {
      fprintf(out, "\nstatic ClipFunction *\n_builtins(long hash)\n{\n");

      if (shared)
      {
	 fprintf(out, "\tClipFunction *rp = 0;\n");
	 for (i = nlibs.count_of_Coll - 1; i >= 0; i--)
	 {
		 char *s = (char *) nlibs.items_of_Coll[i];

	    fprintf(out, "\trp = _clip_builtin_%s ( hash );\n", s);
	    fprintf(out, "\tif ( rp )\n\t\treturn rp;\n");
	 }
      }

      fprintf(out, "\n\tswitch( hash )\n\t{\n");
		for (i = 0; i < names.count_of_Coll; ++i)
      {
			VAR(char, s, names.items_of_Coll[i]);

	 if (!memcmp(s + 5, "INIT_", 5) || !memcmp(s + 5, "EXIT_", 5))
	    continue;
	 fprintf(out, "\tcase %ld:\n", (long) hashstr(s + 5));
	 fprintf(out, "\t\treturn %s;\n", s);
      }
      fprintf(out, "\tdefault:\n\t\treturn 0;\n");
      fprintf(out, "\t}\n");
      fprintf(out, "};\n\n");
   }