Example #1
0
void Trap::CreateHiddenTrigger()
{
	if(hiddenTrigger)
		return;

	const NPCType *base_type = database.GetNPCType(500);
	NPCType *make_npc = new NPCType;
	memcpy(make_npc, base_type, sizeof(NPCType));
	make_npc->max_hp = 100000;
	make_npc->cur_hp = 100000;
	strcpy(make_npc->name, "a_trap");
	make_npc->runspeed = 0.0f;
	make_npc->bodytype = BT_Special;
	make_npc->race = 127;
	make_npc->gender = 0;
	make_npc->loottable_id = 0;
	make_npc->npc_spells_id = 0;
	make_npc->d_meele_texture1 = 0;
	make_npc->d_meele_texture2 = 0;
	make_npc->trackable = 0;
	make_npc->level = level;
	strcpy(make_npc->special_abilities, "19,1^20,1^24,1^25,1");
	NPC* npca = new NPC(make_npc, 0, x, y, z, 0, FlyMode3);
	npca->GiveNPCTypeData(make_npc);
	entity_list.AddNPC(npca);

	hiddenTrigger = npca;
	ownHiddenTrigger = true;
}
void append_redirect(char input[]){
		//printf("!1\n");
                int fd;
                char *tok;
                char path[256];
                char command[256];

                memset(path,0,256);
                memset(command,0,256);


                tok=strtok(input,">");
		//printf("!2%s\n",tok);
                strcpy(command,tok);
		
                tok = strtok(NULL,">");
		//printf("!3%s\n",tok);
		if(tok[0] == ' '){
	                strcpy(path,tok+1);			
		}
		else{
			
		      strcpy(path,tok);		
		}
		//printf("!4%s\n",path);
                fd = open(path,O_RDWR|O_CREAT|O_APPEND);
                close(1);
                dup(fd);
                close(fd);
                execmd(command);

          


}
Example #3
0
void DrasculaEngine::checkObjects() {
	int l, veo = 0;

	for (l = 0; l < numRoomObjs; l++) {
		if (mouseX > x1[l] && mouseY > y1[l]
				&& mouseX < x2[l] && mouseY < y2[l]
				&& visible[l] == 1 && isDoor[l] == 0) {
			strcpy(textName, objName[l]);
			_hasName = true;
			veo = 1;
		}
	}

	if (mouseX > curX + 2 && mouseY > curY + 2
			&& mouseX < curX + curWidth - 2 && mouseY < curY + curHeight - 2) {
		if (currentChapter == 2 || veo == 0) {
			strcpy(textName, "hacker");
			_hasName = true;
			veo = 1;
		}
	}

	if (veo == 0)
		_hasName = false;
}
Example #4
0
/* pos is 0 to put at top, or 1 to put next to top */
void
insert_riplist (char* url, int pos)
{
    int i;
    int oldpos;

    debug_printf ("Insert riplist (0)\n");

    /* Don't add if it's the relay stream */
    if (url_is_relay (url)) return;

    debug_printf ("Insert riplist (1): %d %s\n", pos, url);
    debug_riplist ();

    /* oldpos is previous position of this url. Don't shift if 
       it's already at that position or above. */
    oldpos = find_url_in_riplist (url);
    if (oldpos == -1) {
	oldpos = RIPLIST_LEN - 1;
    }
    if (oldpos <= pos) return;

    /* Shift the url to the correct position */
    for (i = oldpos; i > pos; i--) {
	strcpy(g_gui_prefs.riplist[i], g_gui_prefs.riplist[i-1]);
    }
    strcpy(g_gui_prefs.riplist[pos], url);

    debug_printf ("Insert riplist (2): %d %s\n", pos, url);
    debug_riplist ();

    /* Rebuild the history menu */
    populate_history_popup ();
}
Example #5
0
int EventHub::read_notify(int nfd)
{
#ifdef HAVE_INOTIFY
    int res;
    char devname[PATH_MAX];
    char *filename;
    char event_buf[512];
    int event_size;
    int event_pos = 0;
    struct inotify_event *event;

    LOGV("EventHub::read_notify nfd: %d\n", nfd);
    res = read(nfd, event_buf, sizeof(event_buf));
    if(res < (int)sizeof(*event)) {
        if(errno == EINTR)
            return 0;
        LOGW("could not get event, %s\n", strerror(errno));
        return 1;
    }
    //printf("got %d bytes of event information\n", res);

    strcpy(devname, device_path);
    filename = devname + strlen(devname);
    *filename++ = '/';

    while(res >= (int)sizeof(*event)) {
        event = (struct inotify_event *)(event_buf + event_pos);
        //printf("%d: %08x \"%s\"\n", event->wd, event->mask, event->len ? event->name : "");
        if(event->len) {
            strcpy(filename, event->name);
#ifdef HAVE_TSLIB
            if (!strcmp(filename, "pointercal")) {
                if (mTS->fd)
                    ts_reload(mTS);
                inotify_rm_watch(mFDs[0].fd, res);
                res = inotify_add_watch(mFDs[0].fd, pointercal_path, IN_MODIFY);
                if(res < 0) {
                    LOGE("could not add watch for %s, %s\n", pointercal_path, strerror(errno));
                }
            } else {
#else
            {
#endif
                if(event->mask & IN_CREATE) {
                    open_device(devname);
                }
                else {
                    close_device(devname);
                }
            }
#ifdef HAVE_TSLIB
        } else {
              if (mTS->fd)
                  ts_reload(mTS);
#endif
        }
        event_size = sizeof(*event) + event->len;
        res -= event_size;
        event_pos += event_size;
    }
Example #6
0
size_t
cc_xml_attr_write_to_buffer(const cc_xml_attr * attr, char * buffer, size_t bufsize)
{
  // We assert on mismatches between calculated memory usage and actual memory
  // usage, since this must be calculated correctly for not getting memory corruption
  // on invalid buffer size allocation before writing.
  const char * const origbufferptr = buffer;
  const size_t assumed = cc_xml_attr_calculate_size(attr);
  assert(assumed < bufsize);
  int namelen = strlen(attr->name);
  strcpy(buffer, attr->name);
  buffer += namelen;
  strcpy(buffer, "=\"");
  buffer += 2;
  if (attr->value) {
    int valuelen = strlen(attr->value);
    // FIXME: count quotables, and insert quoting in value string if needed
    strcpy(buffer, attr->value);
    buffer += valuelen;
  }
  buffer[0] = '"';
  buffer += 1;
  size_t used = buffer - origbufferptr;
  assert(used == assumed);
  return used;
}
Example #7
0
static void
load_modules(const char *dirname)
{
    DIR *dir = opendir(dirname);
    if (dir == NULL) {
        return;
    }

    char tmp[PATH_MAX];
    strcpy(tmp, dirname);
    strcat(tmp, "/");
    char *filename = tmp + strlen(dirname) + 1;

    struct dirent *ent;
    while ((ent = readdir(dir)) != NULL) {
        int len = strlen(ent->d_name) - strlen(APKENV_MODULE_SUFFIX);
        if (len > 0) {
            char *suffix = ent->d_name + len;
            if (strcmp(suffix, APKENV_MODULE_SUFFIX) == 0) {
                strcpy(filename, ent->d_name);
                load_module(tmp);
            }
        }
    }
    closedir(dir);
}
Example #8
0
int32_t getline777(char *line,int32_t max)
{
#ifndef _WIN32
    static char prevline[1024];
    struct timeval timeout;
    fd_set fdset;
    int32_t s;
    line[0] = 0;
    FD_ZERO(&fdset);
    FD_SET(STDIN_FILENO,&fdset);
    timeout.tv_sec = 0, timeout.tv_usec = 10000;
    if ( (s= select(1,&fdset,NULL,NULL,&timeout)) < 0 )
        fprintf(stderr,"wait_for_input: error select s.%d\n",s);
    else
    {
        if ( FD_ISSET(STDIN_FILENO,&fdset) > 0 && fgets(line,max,stdin) == line )
        {
            line[strlen(line)-1] = 0;
            if ( line[0] == 0 || (line[0] == '.' && line[1] == 0) )
                strcpy(line,prevline);
            else strcpy(prevline,line);
        }
    }
    return((int32_t)strlen(line));
#else
    fgets(line, max, stdin);
    line[strlen(line)-1] = 0;
    return((int32_t)strlen(line));
#endif
}
Example #9
0
File: hw1.c Project: kepler27/HW1
void changeTeamName(Node ** head, FILE * finTeams)
{
    char temp[MAX];
    char * longName;
    char * myStringCopy;
    Node * first = *head;

    for(; first != NULL; first = first->next)
    {
        fgets(temp, MAX, finTeams);
        while(fgets(temp, MAX, finTeams)!= NULL)
        {
            myStringCopy = (char *)calloc(strlen(temp)+1, sizeof(char));
            strcpy(myStringCopy,temp);
            char * toke = strtok(myStringCopy, ",");
            longName = (char*) calloc(strlen(toke)+1,sizeof(char));
            strcpy(longName, toke);
            toke = strtok(NULL, ",");
            stripRN(toke);
            if(strcasecmp(((Player*)(first->data))->teamName, toke) == 0)
            {
                free(myStringCopy);
                rewind(finTeams);
                free(((Player*)(first->data))->teamName);
                ((Player*)(first->data))->teamName = longName;
                break;
            }
            free(longName);
            free(myStringCopy);
        }
    }
}
Example #10
0
void handleClient(void *socketPointer) {
    int sock = (int)socketPointer;
    int error;
    char buffer[1024];
    char line[1024];
    struct Message receivedMessage, sentMessage;
    FILE *file;
    error = recv(sock, buffer, sizeof(buffer), 0);
    if (error < 0) {
        perror("Failed to receive");
        exit(1);
    }
    memcpy(&receivedMessage, buffer, sizeof(receivedMessage));

    file = fopen(receivedMessage.content, "r");
    while (fgets(line, sizeof(line), file)) {
        pthread_mutex_lock(&mutex);
        if (strlen(line) > strlen(longestLine)) {
            strcpy(longestLine, line);
        }
        strcpy(sentMessage.content, longestLine);
        pthread_mutex_unlock(&mutex);
    }
    fclose(file);
    memcpy(buffer, &sentMessage, sizeof(sentMessage));
    error = send(sock, buffer, sizeof(buffer), 0);
    if (error < 0) {
        perror("Failed to send");
        exit(1);
    }
    close(sock);
}
Example #11
0
int parse_uri(char* uri, char* filename, char* cgiargs) {
    char* ptr;
    if (!strstr(uri, "cgi-bin")) {
        //static content
        strcpy(cgiargs, "");
        strcpy(filename, ".");
        strcat(filename, uri);
        if (uri[strlen(uri) - 1] == '/') {
            strcat(filename, "home.html");
        }
        return 1;
    } else {
        // dynamic content
        ptr = index(uri, '?');
        if (ptr) {
            strcpy(cgiargs, ptr + 1);
            *ptr = '\0';
        } else {
            strcpy(cgiargs, "");
        }
        strcpy(filename, ".");
        strcat(filename, uri);
        return 0;
    }
}
void HttpHandler::responseOptionsMethod()
{
    if(this->isNew)
    {
        if(this->serverHttp10)
            this->dataLeft = strlen(SUPPORTED_METHODS_HTTP10);
        else
            this->dataLeft = strlen(SUPPORTED_METHODS_HTTP11);
        this->fileSize = this->dataLeft;
        this->bufferSize = this->dataLeft;
        this->statusCode = 200;
        composeStatusLine();
        composeHeader();
    }
    else
    {
        if(this->msgBuffer != NULL)
        {
            delete[] this->msgBuffer;
            this->msgBuffer = NULL;
        }
        this->msgBuffer = new char[this->dataLeft];
        if(this->serverHttp10)
            strcpy(this->msgBuffer, SUPPORTED_METHODS_HTTP10);
        else
            strcpy(this->msgBuffer, SUPPORTED_METHODS_HTTP11);
        this->dataLeft = 0;
        this->statusLine = NULL;
        this->header = NULL;
    }
    composeResponse();
}
int mongo_get_documents(mongoc_client_t *client, char *database, char *collection_name, bson_t *query,
                        query_result **result) {
    mongoc_collection_t *collection;
    mongoc_cursor_t *cursor;
    const bson_t *doc;
    char *str;
    int index = 0;
    collection = mongoc_client_get_collection(client, database, collection_name);

    cursor = mongoc_collection_find(collection, MONGOC_QUERY_NONE, 0, 0, 0, query, NULL, NULL);

    query_result *current = *result;
    while (mongoc_cursor_next(cursor, &doc)) {
        str = bson_as_json(doc, NULL);
        if (index == 0) {
            (*result)->document = malloc(strlen(str) + 1);
            strcpy((*result)->document, str);
            (*result)->next = NULL;
        }
        else {
            current->next = malloc(sizeof(query_result));
            current->next->document = malloc(strlen(str) + 1);
            strcpy(current->next->document, str);
            current->next->next = NULL;
            current = current->next;
        }
        index++;
        bson_free(str);
    }

    mongoc_cursor_destroy(cursor);
    mongoc_collection_destroy(collection);
    return 0;
}
Example #14
0
File: elf.c Project: rui314/8cc-old
static void add_reloc(Elf *elf) {
    char name[100];
    for (int i = 0; i < LIST_LEN(elf->sections); i++) {
        Section *sect = LIST_REF(elf->sections, i);
        if (LIST_LEN(sect->rels) == 0)
            continue;
        String *b = make_string();
        for (int j = 0; j < LIST_LEN(sect->rels); j++) {
            Reloc *rel = LIST_REF(sect->rels, j);
            o8(b, rel->off);
            if (rel->sym) {
                o8(b, ELF64_R_INFO(find_symbol(elf, rel->sym)->index, rel->type));
            } else {
                o8(b, ELF64_R_INFO(rel->section->symindex, rel->type));
            }
            o8(b, rel->addend);
        }

        strcpy(name, ".rela");
        strcpy(name + 5, sect->name);
        Section *relsec = make_section(name, SHT_RELA);
        relsec->link = elf->symtabnum;
        relsec->info = i + 1;
        relsec->body = b;
        relsec->entsize = 24;
        relsec->align = 4;
        add_section(elf, relsec);
    }
}
Example #15
0
char *diag_get_command_line(char **argv)
{
	assert(argv);

	char *line = diag_malloc(32768);
	char *lp = line;
	int i;
	for (i = 0; argv[i]; i++) {
		const char *s = argv[i];
		int slen = (int)strlen(s);
		if (lp + slen >= line + 32768) {
			diag_free(line);
			return NULL;
		}
		if (i > 0) {
			*lp++ = ' ';
		}
		if (contains_space(s)) {
			*lp++ = '"';
			strcpy(lp, s);
			lp += slen;
			*lp++ = '"';
		} else {
			strcpy(lp, s);
			lp += slen;
		}
	}
	*lp = '\0';
	return line;
}
Example #16
0
// setenv command implementation
void executeSetenv(Cmd c)
{	
	int i = 0;
	if(c->args[1] == NULL)
	{
		extern char **environ;
		while(environ[i] != NULL)
		{
			printf("%s\n",environ[i]);
			i++;
		}
		return;
	}
	else
	{
		char* secondArg = (char *)malloc(1000);
		if(c->args[2] == NULL){
                        strcpy(secondArg,"");
		}
		else
		{
			strcpy(secondArg,c->args[2]);
		}
		if(setenv(c->args[1],secondArg,1) == -1){
			printf("Error in setting environment variable\n");
			return;		
		}
	}
}
Example #17
0
int main(int argc, char *argv[])
{
	char file[100];
	char target[100];
	char line[1000];
	FILE *fp1, *fp2;

	strcpy(file, argv[1]);
	strcpy(target, argv[2]);

	fp1 = fopen(file, "r");
	fp2 = fopen(target, "w");
	if (!fp1 || !fp2)
	{
		printf("Fail to open the file!\n");
		exit(-1);
	}
	
	while (fgets(line, 1000, fp1))
	{
		if (line[0] != '#')
			fputs(line, fp2);
	}

	fclose(fp1);
	fclose(fp2);

	return 0;
}
Example #18
0
// cd command implementation
void executeCD(Cmd c)
{	
	char *homeDirPath = (char *)malloc(1000);
  	strcpy(homeDirPath, getenv("HOME"));
	if(c->args[1] == NULL || !strcmp(c->args[1],"~"))
	{
		c->args[1] = malloc(strlen(homeDirPath));
		strcpy(c->args[1],homeDirPath);
	}
	else if(c->args[1][0] == '~')
	{
		char *temp,temp1[500];
		int tlen = 0;
		temp = strtok(c->args[1],"~");
		if(temp){
			tlen = strlen(temp);
			c->args[1] = malloc(strlen(homeDirPath)+tlen);
			strcpy(c->args[1],strcat(homeDirPath,temp));
		}
	}
        if (chdir(c->args[1]) == -1) {
     		 if(getcwd(currWorkDir, 1024)!=NULL){
        		printf("Error in chdir,Stayed in: %s\n",currWorkDir);
		 }
        }
}
Example #19
0
int test_batch(cl_cluster *clc)
{
	cl_rv rv;
	cl_bin bins[3];
	cl_object keys[2];
	cf_digest digests[2];
	char *userData = "foobar";

	citrusleaf_object_init_str(&keys[0],myKey);
	citrusleaf_object_init_str(&keys[1],myKey2);

	citrusleaf_object_init(&bins[0].object); 
	citrusleaf_object_init(&bins[1].object); 
	citrusleaf_object_init(&bins[2].object);

	strcpy(&bins[0].bin_name[0], bin1); 	
	strcpy(&bins[1].bin_name[0], bin2); 
	strcpy(&bins[2].bin_name[0], bin3); 

	citrusleaf_calculate_digest(myset, &keys[0], &digests[0]);
	citrusleaf_calculate_digest(myset, &keys[1], &digests[1]);
	
	rv = citrusleaf_get_many_digest(clc, (char *)ns, digests, 2, bins, 3, false, batch_cb, userData);

	if( rv != CITRUSLEAF_OK ){
		printf(" TEST FAILS - get many (batch) fails with %d\n", rv);
		return -1;
	}

	return 0;
}
Example #20
0
// where command implementation
void executeWhere(Cmd c)
{
	char *path = getenv("PATH");
	char dupPath[500],cmd_path[500]="";
	int i = -1 ;
	int j=0;
	while(j<8){
		if(!strcmp(c->args[1],builtInCommands[j])){
			i = j;
		}
		j++;
	}
	if(i!=-1)
	{
		printf("%s:built-in command\n",builtInCommands[i]);
	}	
	strcpy(dupPath,path);
	char* splittedPath = strtok(dupPath,":");
	while(splittedPath != NULL)
	{
		strcpy(cmd_path,splittedPath);
		strcat(cmd_path,"/");
		strcat(cmd_path,c->args[1]);
		if(!access(cmd_path,F_OK))
		{
		    printf("%s\n",cmd_path);
		}
		splittedPath = strtok(NULL,":");
	}
}
Example #21
0
void
UpdateNotRippingDisplay (HWND hwnd)
{
#if defined (commentout)
    WINAMP_INFO winfo;

    // debug_printf ("UNRD begin\n");
    if (winamp_get_info (&winfo, m_guiOpt.use_old_playlist_ret)) {
        debug_printf ("UNRD got winamp stream: %s\n", winfo.url);
	if (!strcmp (winfo.url, m_winamp_stream_cache)) {
	    debug_printf ("UNRD return - cached\n");
	    return;
	}
	strcpy (m_winamp_stream_cache, winfo.url);
	
	if (!url_is_stream(winfo.url) || url_is_relay (winfo.url)) {
	    debug_printf ("UNRD not_stream/is_relay: %d\n", g_rmo.url[0]);
	    if (g_rmo.url[0]) {
		set_ripping_url (g_rmo.url);
	    } else {
		set_ripping_url (0);
	    }
	} else {
	    debug_printf ("UNRD setting g_rmo.url: %s\n", g_rmo.url);
	    strcpy(g_rmo.url, winfo.url);
	    insert_riplist (winfo.url, 0);
	    set_ripping_url (winfo.url);
	}
    }
#endif
}
Example #22
0
int recv_cjhb::login(char * gddm,int type)
{
	if(INVALID_SOCKET==m_sock) return -1;
	//send login req
	cjhb_req cr;
	cr.FuncType=ftLogin;
	strcpy(cr.login.gdzh,gddm);
	cr.login.type=type;
	//recv ret code
	if(!this->SendBuffer((char*)&cr,sizeof(cr)))
		return -1; //发送失败

	clhb_ans ca;
	if(!this->RecvBuffer((char*)&ca,sizeof(ca)))
		return -2; //接收失败

	if(ca.AnsCount==1 && ca.CurAnsNo==1 && ca.RetVal==0) 
	{
		strcpy(m_gddm,gddm);
		m_type=type;
		End();
		Begin();
		return 0;
	}
	return -3;
}
Example #23
0
static int GetSysParam(const char *para,char *value)
{
    int ret;
    ST_CPACK aPack,sPack;
    memset(&sPack,0,sizeof sPack);
    memset(&aPack,0,sizeof aPack);

    ResetNormalCPack(&sPack,0,1);
    SetHeadCol(&sPack,F_SNAME,F_SNAME2,0);
    sPack.head.RequestType = 850007;
    strcpy(sPack.pack.sname,"GDCT");
    strcpy(sPack.pack.sname2,para);
    ret = ExtCall(0,g_mainsvr_drtpno,g_mainsvr_func,0,3,&sPack,&aPack,NULL);
    if(ret>=0)
    {
        if(aPack.head.retCode!=0)
            return aPack.head.retCode;
        strncpy(value,aPack.pack.vsvarstr0,128);
        return 0;
    }
    else
    {
        return -1;
    }
}
Example #24
0
// return the number of files that match
int vfsGetFileCount (const char *filename)
{
  int i, count = 0;
  char fixed[NAME_MAX], tmp[NAME_MAX];
  GSList *lst;
  
  strcpy (fixed, filename);
  vfsFixDOSName (fixed);
  g_strdown (fixed);
  
  for (lst = g_pakFiles; lst != NULL; lst = g_slist_next (lst))
  {
    VFS_PAKFILE* file = (VFS_PAKFILE*)lst->data;
    
    if (strcmp (file->name, fixed) == 0)
      count++;
  }
  
  for (i = 0; i < g_numDirs; i++)
  {
    strcpy (tmp, g_strDirs[i]);
    strcat (tmp, fixed);
    if (access (tmp, R_OK) == 0)
      count++;
  }
  
  return count;
}
void execmd(char input[])
{
		
                char *token;
                char *result[256];
               
		if(strstr(input,"cd")){
			printf("into cd command\n");
              		char *token = strtok(input," ");
              		token = strtok(NULL," ");
        	        if(chdir(token) < 0){
	                      perror("wrong directory");
	                }       

		}
		else{
		        token = strtok(input," ");
		        result[0] = (char*)malloc(strlen(token)+1);
			strcpy(result[0],token);
		        int i=1;
		        while(token=strtok(NULL," ")){
		               result[i]=(char *)malloc(strlen(token)+1);
		               strcpy(result[i],token);
		               i++;
		        }
		        result[i] = NULL;
			execvp(result[0],result);				
		}

 
}
Example #26
0
/*---------------------------------------------------------------------------
 * int	osd_path_split( const char *path, char dir[], char file[],
 *			int size )
 *	処理内容:
 *		path の最後の '/' より前を dir、後ろを file にセットする
 *---------------------------------------------------------------------------*/
int	osd_path_split( const char *path, char dir[], char file[], int size )
{
  int	pos = strlen( path );

  /* dir, file は十分なサイズを確保しているはずなので、軽くチェック */
  if( pos==0 || size <= pos ){
    dir[0]  = '\0';
    file[0] = '\0';
    strncat( file, path, size-1 );
    fprintf( stderr, "internal overflow %d\n",__LINE__ );
    return 0;
  }


  do{					/* '/' を末尾から探す 		*/
    if( path[ pos-1 ] == '/' ) break;
    pos --;
  } while( pos );

  if( pos ){				/* '/' が見つかったら		*/
    strncpy( dir, path, pos );			/* 先頭〜'/'までをコピー*/
    dir[pos] = '\0';				/* '/' も含まれます	*/
    strcpy( file, &path[pos] );

  }else{				/* '/' が見つからなかった	*/
    dir[0]  = '\0';				/* ディレクトリは ""	*/
    strcpy( file, path );			/* ファイルは path全て	*/
  }

  return 1;
}
void out_redirect(char input[]){
                int fd;
                char *tok;
		char path[256];
		char command[256];

		memset(path,0,256);
		memset(command,0,256);


                tok=strtok(input,">");
	        strcpy(command,tok);
		
                tok = strtok(NULL," ");
		if(tok[0] == ' '){
	                strcpy(path,tok+1);			
		}
		else{
			
		      strcpy(path,tok);		
		}
                
   

                fd = open(path,O_WRONLY|O_CREAT);
                close(1);
                dup(fd);
                close(fd);
                execmd(command);
		

}
Example #28
0
void init(){
	/*
	 *插入read(),write()函数
	 */
	char *read_name = (char*)malloc(20);
	char *write_name = (char*)malloc(20);
	char *field_name = (char*)malloc(20);
	strcpy(read_name,"read");
	strcpy(write_name,"write");
	strcpy(field_name,"a");
	Type read_type = (Type)malloc(sizeof(struct Type_));
	read_type->kind = basic;
	read_type->u.basic = 0;
	FieldList read_func = (FieldList)malloc(sizeof(struct FieldList_));
	read_func->name = read_name;
	read_func->type = read_type;
	read_func->tail = NULL;
	insertFunc(read_func);

	Type write_type = (Type)malloc(sizeof(struct Type_));
	write_type->kind = basic;
	write_type->u.basic = 0;
	Type field_type = (Type)malloc(sizeof(struct Type_));
	field_type->kind = basic;
	field_type->u.basic = 0;
	FieldList write_func = (FieldList)malloc(sizeof(struct FieldList_));
	FieldList write_field = (FieldList)malloc(sizeof(struct FieldList_));
	write_field->name = field_name;
	write_field->type = field_type;
	write_field->tail = NULL;
	write_func->name = write_name;
	write_func->type = write_type;
	write_func->tail = write_field;
	insertFunc(write_func);
}
void FixDumpFileName (XnDevicePrivateData* pDevicePrivateData, XnChar* strFileName)
{
	XnChar strTempFileName[255];
	XnChar* nFind = 0;

	strcpy(strTempFileName, strFileName);

	nFind = strstr(strFileName, "SNSNSN");
	if (nFind != 0)
	{
		nFind[0] = 0;
		sprintf (strTempFileName, "%s%s%s", strFileName, pDevicePrivateData->pSensor->GetFixedParams()->GetSensorSerial(), nFind+6);

		strcpy(strFileName, strTempFileName);		
	}

	nFind = strstr(strFileName, "SETSET");
	if (nFind != 0)
	{
		XnInt32 nSet = 1;		
		XnBool bExists = TRUE;

		nFind[0] = 0;

		while (bExists == TRUE)
		{
			sprintf (strTempFileName, "%sSET%04d%s", strFileName, nSet, nFind+6);
			nSet++;

			xnOSDoesFileExist(strTempFileName, &bExists);
		}
			
		strcpy(strFileName, strTempFileName);		
	}
}
void copy_amino_allocating(amino_t *amino_dest, const amino_t *amino_source){
	/* This function copies an amino from amino_source to amino_dest allocating
	 * if necessary.
	 *  The difference this function and copy_amino function is the last does
	 *  not allocate.
	 *  This function is used in build_initial_population_lib.c file
	 */
	amino_dest->HP = amino_source->HP;
	strcpy(amino_dest->aminoacido, amino_source->aminoacido);
	strcpy(amino_dest->chainid,amino_source->chainid);
	strcpy(amino_dest->idl3, amino_source->idl3);
	amino_dest->id = amino_source->id;
	amino_dest->number_late = amino_source->number_late;
	if (amino_source->late != NULL){
		if (amino_dest->late != NULL){
			fatal_error("amino_dest in copy_amino function can not be allocated before its late");
		}
		amino_dest->late = Malloc(float,amino_dest->number_late);
		for (int i=0;i<amino_dest->number_late;i++){
			amino_dest->late[i] = amino_source->late[i];
		}
	}
	amino_dest->pos_late = amino_source->pos_late;
	amino_dest->phi = amino_source->phi;
	amino_dest->psi = amino_source->psi;
	amino_dest->omega = amino_source->omega;
}