ObjectData_T *read_ObjData( char *name, int *objectnum ) { FILE *fp; ObjectData_T *object; char buf[256], buf1[256]; int i; printf("Opening Data File %s\n",name); if( (fp=fopen(name, "r")) == NULL ) { printf("Can't find the file - quitting \n"); return(0); } get_buff(buf, 256, fp); if( sscanf(buf, "%d", objectnum) != 1 ) {fclose(fp); return(0);} printf("About to load %d Models\n",*objectnum); object = (ObjectData_T *)malloc( sizeof(ObjectData_T) * *objectnum ); if( object == NULL ) return(0); for( i = 0; i < *objectnum; i++ ) { object[i].visible = 0; get_buff(buf, 256, fp); if( sscanf(buf, "%s", object[i].name) != 1 ) { fclose(fp); free(object); return(0); } printf("Read in No.%d \n", i+1); get_buff(buf, 256, fp); if( sscanf(buf, "%s", buf1) != 1 ) { fclose(fp); free(object); return(0);} if( (object[i].id = arLoadPatt(buf1)) < 0 ) {fclose(fp); free(object); return(0);} get_buff(buf, 256, fp); if( sscanf(buf, "%lf", &object[i].marker_width) != 1 ) { fclose(fp); free(object); return(0); } get_buff(buf, 256, fp); if( sscanf(buf, "%lf %lf", &object[i].marker_center[0], &object[i].marker_center[1]) != 2 ) { fclose(fp); free(object); return(0); } } fclose(fp); return( object ); }
int user_read(t_server *server, t_client *cl) { char buf[RSIZE]; char aligned[cl->rb->size + 1]; char *tmp; char *save; ssize_t retv; tmp = aligned; if ((retv = read(cl->fd, buf, RSIZE)) <= 0) return (disconnect_user(server, cl)); fill_ringbuffer(cl->rb, buf, retv); if ((tmp = get_buff(cl->rb)) == NULL) return (-1); save = tmp; while ((retv = get_char_pos(tmp, '\n')) != -1) { tmp[retv] = '\0'; if (process_input(server, cl, tmp) < -1) { queue_push(&cl->queue, "ko\n"); return (disconnect_user(server, cl)); } tmp = &tmp[retv + 1]; } update_ringbuffer(cl->rb, save, tmp); return (0); }
int get_next_line(const int fd, char **line) { char *temp; char *ptr; int ret; static t_file file; if (file.fd != fd) { file.fd = fd; ft_memdel((void**)&file.data); } if ((ret = get_buff(fd, &file.data)) == -1) return (ret); if (file.data == NULL) return (0); if (ft_strlen(file.data) == 0) return (0); ptr = ft_strchr(file.data, '\n'); *line = ft_strndup(file.data, ptr - file.data); temp = ft_strsub(file.data, ptr - file.data + 1, ft_strlen(file.data)); ft_memdel((void**)&file.data); file.data = temp; return (1); }
int my_select(t_list *list, struct termios old) { int i; char buff[2]; i = 0; while (i < 1) { screen_clear(); buff[0] = 0; buff[1] = 0; buff[2] = 0; show_list(list); if (read(0, buff, 3) == -1) { my_putstr("Error: read failled"); return (0); } else if (get_buff(buff, &i, list, old) == -1) return (0); } if (i == 2) show_selected(list); return (0); }
ssize_t send_msg(int sock_d, CalcMessage *c_msg) { int buff_size; uint8_t *buff = get_buff(c_msg, &buff_size); ssize_t wr_bytes = write(sock_d, buff, buff_size); free(buff); return wr_bytes; }
int client::pwd() { int res = 0; char path[BUFFSIZE] = {0}; if( m_guider.is_at_local() ) { cout << (NULL != m_guider.pwd(path, BUFFSIZE) ? path : " ") << endl; } else { //reply(PT_PWD); m_buff.clear(); // Add the pack type. m_buff.push_front(PT_PWD); // Add the checkcode. m_buff.push_back(PT_PWD); if(-1 == send_data()) { return -1; // Send error. } // Receive path information. if( -1 == recv_data() ) { ;// Error } if( is_pack_type(PT_DATA, m_analyser.get_pack_type()) ) { // Delete the pack type. m_buff.pop_front(); get_buff(path, BUFFSIZE); cout << path << endl; } else { ; // Uninterested package. } } return res; }
int get_next_line(const int fd, char **line) { long int eof; if (BUFF_SIZE > MAX_BUFF || BUFF_SIZE < 1) return (-1); eof = get_buff(fd, line); if (eof == -1) return (-1); if (eof == -2) return (0); return (1); }
int file_buff_write(void * buf,Inode* p_inode,int offset,int count) { // 1、确定操作位置 if(offset < 0 || offset >= FILE_MAX_SIZE) { printk("write pos out of file offset : %x\n",offset); return -1; // 位置超出范围 } // 2、写入。在缓冲区中操作,如果文件不在缓冲区内,则先读入缓冲区 int buff_offset = offset % BUFF_SIZE; // 确定缓冲区中的操作位置 int buf_offset = 0; // 待写数据中的偏移 int cnt = 0; // 已写入字节数 while(count > 0) { // 1、搜索待写文件是否在缓冲区,如果不在就将其读入缓冲区 BUFF_HEAD* p_bh = scan_buff(p_inode,offset); if(p_bh == 0) { p_bh = get_buff(p_inode,offset); // 申请缓冲区 if(p_bh == 0) return -1; // 缓冲区用完 read_buff(p_bh); // 文件读入缓冲区 } // 2、此时待写文件已经在缓冲区,在缓冲区中写入内容 void* buff_base = p_bh->buff_base; // 缓冲区地址 int buff_remin = BUFF_SIZE - buff_offset; // 缓冲区剩余字节数 if(buff_remin >= count) // 当前缓冲区能容纳所有剩余数据 { memcopy(buff_base + buff_offset,buf + buf_offset,count); cnt += count; // 剩余数据全部写入,然后返回 p_bh->dirty = 1; // 文件缓冲“脏”标志 return cnt; } else // 当前缓冲区不能容纳所有剩余数据 { memcopy(buff_base + buff_offset,buf + buf_offset,buff_remin); buff_offset = 0; // 写满当前缓冲区后循环写下一个缓冲区 buf_offset += buff_remin; count -= buff_remin; cnt += buff_remin; offset += buff_remin; p_bh->dirty = 1; // 文件缓冲“脏”标志 } } return 0; // 不可能到达这里 }
int file_buff_read(void * buf,Inode* p_inode,int offset,int count) { // 1、确定操作位置 if(offset < 0 || offset >= FILE_MAX_SIZE) { printk("read pos out of file offset : %x\n",offset); return -1; // 位置超出范围 } // 2、读取。在缓冲区中操作,如果文件不在缓冲区内,则先读入缓冲区 int buff_offset = offset % BUFF_SIZE; // 确定缓冲区中的操作位置 int buf_offset = 0; // 待读数据中的偏移 int cnt = 0; // 已读取字节数 while(count > 0) { // 1、搜索待读文件是否在缓冲区,如果不在就将其读入缓冲区 BUFF_HEAD* p_bh = scan_buff(p_inode,offset); if(p_bh == 0) { p_bh = get_buff(p_inode,offset); // 申请缓冲区 if(p_bh == 0) return -1; // 缓冲区用完 read_buff(p_bh); // 文件读入缓冲区 //printk("111 i_num : %d buff_base:%x offset: %d \n",p_bh->p_inode->i_num,p_bh->buff_base,p_bh->offset); } // 2、此时待读文件已经在缓冲区,在缓冲区中读取内容 void* buff_base = p_bh->buff_base; // 缓冲区地址 int buff_remin = BUFF_SIZE - buff_offset; // 缓冲区剩余字节数 if(buff_remin >= count) // 当前缓冲区能容纳所有剩余数据 { memcopy(buf + buf_offset,buff_base + buff_offset,count); cnt += count; // 剩余数据全部读取,然后返回 return cnt; } else // 当前缓冲区不能容纳所有剩余数据 { memcopy(buf + buf_offset,buff_base + buff_offset,buff_remin); buff_offset = 0; // 读完当前缓冲区后循环读取下一个缓冲区 buf_offset += buff_remin; count -= buff_remin; cnt += buff_remin; offset += buff_remin; } } return 0; // 不可能到达这里 }
void server::cd() { if(m_guider.is_at_local() ) { char path[BUFFSIZE] = {0}; get_buff(path, BUFFSIZE); if( -1 == m_guider.cd(path) ) { reply(PT_NOENT); } else { reply(PT_OK); } } }
void *consumer(void *arg) { while(1) { pthread_mutex_lock(&m); while(numrequests == 0) { pthread_cond_wait(&fill, &m); } // service request buff_t* requestbuff = get_buff(); pthread_cond_signal(&empty); pthread_mutex_unlock(&m); requestHandle(requestbuff); Close(requestbuff->fd); free(requestbuff); } }
int arVrmlLoadFile(const char *file) { FILE *fp; openvrml::browser * myBrowser = 0; char buf[256], buf1[256]; char buf2[256]; int id; int i; if( init ) { for( i = 0; i < AR_VRML_MAX; i++ ) viewer[i] = NULL; init = 0; } for( i = 0; i < AR_VRML_MAX; i++ ) { if( viewer[i] == NULL ) break; } if( i == AR_VRML_MAX ) return -1; id = i; if( (fp=fopen(file, "r")) == NULL ) return -1; get_buff(buf, 256, fp); if( sscanf(buf, "%s", buf1) != 1 ) {fclose(fp); return -1;} for( i = 0; file[i] != '\0'; i++ ) buf2[i] = file[i]; for( ; i >= 0; i-- ) { if( buf2[i] == '/' ) break; } buf2[i+1] = '\0'; sprintf(buf, "%s%s", buf2, buf1); myBrowser = new openvrml::browser(std::cout, std::cerr); if( !myBrowser) {fclose(fp); return -1;} std::vector<std::string> uri(1, buf); std::vector<std::string> parameter; myBrowser->load_url(uri, parameter); viewer[id] = new arVrmlViewer(*myBrowser); if(!viewer[id]) { delete myBrowser; fclose(fp); return -1; } strcpy( viewer[id]->filename, buf ); get_buff(buf, 256, fp); if( sscanf(buf, "%lf %lf %lf", &viewer[id]->translation[0], &viewer[id]->translation[1], &viewer[id]->translation[2]) != 3 ) { delete viewer[id]; viewer[id] = NULL; fclose(fp); return -1; } get_buff(buf, 256, fp); if( sscanf(buf, "%lf %lf %lf %lf", &viewer[id]->rotation[0], &viewer[id]->rotation[1], &viewer[id]->rotation[2], &viewer[id]->rotation[3]) != 4 ) { delete viewer[id]; viewer[id] = NULL; fclose(fp); return -1; } get_buff(buf, 256, fp); if( sscanf(buf, "%lf %lf %lf", &viewer[id]->scale[0], &viewer[id]->scale[1], &viewer[id]->scale[2]) != 3 ) { delete viewer[id]; viewer[id] = NULL; fclose(fp); return -1; } fclose(fp); return id; }
char * client::get_title_info(char * info, int len) { if(NULL == info || len <= 0) { cerr << "error arguments in " << __FILE__ << " : " << __LINE__ << endl; return NULL; } char path[BUFFSIZE] = {0}; if(m_guider.is_at_local() ) { if(NULL == m_guider.pwd(path, BUFFSIZE)) { return NULL; } } else { m_buff.clear(); // Add pack type. m_buff.push_front(PT_PWD); // Add checkcode. m_buff.push_back(PT_PWD); if(-1 == send_data() ) { return NULL; } if( -1 == recv_data() ) { return NULL;// Error } if( is_pack_type(PT_DATA, m_analyser.get_pack_type()) ) { // Delete the pack type. m_buff.pop_front(); get_buff(path, BUFFSIZE); } else { //path[0] = '?'; // Uninterested package. } } bzero(info, len); path[strlen(path) - 1] = '\0'; char *pstr = strrchr(path, '/'); if(NULL != pstr) { strncpy(info, pstr + 1, len); } else { strcpy(info, "~"); } return info; }
AR2MarkerSetT* ar2ReadMarkerSet(char *filename, char *ext, ARPattHandle *pattHandle) { // COVHI10394 FILE *fp = NULL; AR2MarkerSetT *markerSet = NULL; char buf[256], buf1[256] /*, buf2[256]*/; int i, j; char namebuf[512]; sprintf(namebuf, "%s.%s", filename, ext); if ((fp = fopen(namebuf, "r")) == NULL) return NULL; arMalloc(markerSet, AR2MarkerSetT, 1); if (get_buff(buf, 256, fp) == NULL) { free(markerSet); markerSet = NULL; goto done; } if (sscanf(buf, "%d", &(markerSet->num)) != 1) { free(markerSet); markerSet = NULL; goto done; } if (markerSet->num <= 0) { free(markerSet); markerSet = NULL; goto done; } arMalloc(markerSet->marker, AR2MarkerT, markerSet->num); for (i = 0; i < markerSet->num; i++) { if (get_buff(buf, 256, fp) == NULL) { free(markerSet->marker); free(markerSet); markerSet = NULL; goto done; } if (sscanf(buf, "%s", buf1) != 1) { free(markerSet->marker); free(markerSet); markerSet = NULL; goto done; } // ar2UtilDivideExt(buf1, buf, buf2); if ((markerSet->marker[i].pattId = arPattLoad(pattHandle, buf1)) < 0) { free(markerSet->marker); free(markerSet); markerSet = NULL; goto done; } if (get_buff(buf, 256, fp) == NULL) { free(markerSet->marker); free(markerSet); markerSet = NULL; goto done; } if (sscanf(buf, "%f", &(markerSet->marker[i].width)) != 1) { free(markerSet->marker); free(markerSet); markerSet = NULL; goto done; } for (j = 0; j < 3; j++) { if (get_buff(buf, 256, fp) == NULL) { free(markerSet->marker); free(markerSet); markerSet = NULL; goto done; } if (sscanf(buf, "%f %f %f %f", &(markerSet->marker[i].transI2M[j][0]), &(markerSet->marker[i].transI2M[j][1]), &(markerSet->marker[i].transI2M[j][2]), &(markerSet->marker[i].transI2M[j][3])) != 4) { free(markerSet->marker); free(markerSet); markerSet = NULL; goto done; } } } done: fclose(fp); return markerSet; }
int VirtualEnvironmentInit(const char *objectListFile) { int numObjects; FILE *fp; char buf[MAXPATHLEN]; char objectFullpath[MAXPATHLEN]; int i; ARdouble translation[3], rotation[4], scale[3]; int lightingFlag, markerIndex; ARLOGd("Initialising Virtual Environment.\n"); // One-time OSG initialization. if (!VirtualEnvironment_AROSG) { VirtualEnvironment_AROSG = arOSGInit(); if (!VirtualEnvironment_AROSG) { ARLOGe("Error: unable to init arOSG library.\n"); return (0); } } // Locate and open the objects description file. if ((fp = fopen(objectListFile, "r")) == NULL) { ARLOGe("Error: unable to open object data file '%s'.\n", objectListFile); perror(NULL); goto bail1; } else { ARLOGe("Error: open object data file '%s'.\n", objectListFile); } // First line is number of objects to read. numObjects = 0; get_buff(buf, MAXPATHLEN, fp, 1); if (sscanf(buf, "%d", &numObjects) != 1) { ARLOGe("Error: unable to read number of objects to load from object data file.\n"); goto bail2; } // Allocate space for the objects. if (objects) { free(objects); objects = NULL; objectCount = 0; } objects = (VEObject*)calloc(numObjects, sizeof(VEObject)); if (!objects) { goto bail2; } ARLOGd("Reading %d objects.\n", numObjects); for (i = 0; i < numObjects; i++) { // Read in all info relating to the object. // Read model file path (relative to objects description file). if (!get_buff(buf, MAXPATHLEN, fp, 1)) { ARLOGe("Error: unable to read model file name from object data file.\n"); goto bail3; } if (!arUtilGetDirectoryNameFromPath(objectFullpath, objectListFile, sizeof(objectFullpath), 1)) // Get directory prefix, with path separator. { goto bail3; } strncat(objectFullpath, buf, sizeof(objectFullpath) - strlen(objectFullpath) - 1); // Add name of file to open. // Read translation. get_buff(buf, MAXPATHLEN, fp, 1); #ifdef ARDOUBLE_IS_FLOAT if (sscanf(buf, "%f %f %f", &translation[0], &translation[1], &translation[2]) != 3) #else if (sscanf(buf, "%lf %lf %lf", &translation[0], &translation[1], &translation[2]) != 3) #endif { goto bail3; } // Read rotation. get_buff(buf, MAXPATHLEN, fp, 1); #ifdef ARDOUBLE_IS_FLOAT if (sscanf(buf, "%f %f %f %f", &rotation[0], &rotation[1], &rotation[2], &rotation[3]) != 4) #else if (sscanf(buf, "%lf %lf %lf %lf", &rotation[0], &rotation[1], &rotation[2], &rotation[3]) != 4) #endif { goto bail3; } // Read scale. get_buff(buf, MAXPATHLEN, fp, 1); #ifdef ARDOUBLE_IS_FLOAT if (sscanf(buf, "%f %f %f", &scale[0], &scale[1], &scale[2]) != 3) #else if (sscanf(buf, "%lf %lf %lf", &scale[0], &scale[1], &scale[2]) != 3) #endif { goto bail3; } // Look for optional tokens. A blank line marks end of options. lightingFlag = 1; markerIndex = -1; while (get_buff(buf, MAXPATHLEN, fp, 0) && (buf[0] != '\0')) { if (strncmp(buf, "LIGHTING", 8) == 0) { if (sscanf(&(buf[8]), " %d", &lightingFlag) != 1) { ARLOGe("Error in object file: LIGHTING token must be followed by an integer >= 0. Discarding.\n"); } } else if (strncmp(buf, "MARKER", 6) == 0) { if (sscanf(&(buf[6]), " %d", &markerIndex) != 1) { ARLOGe("Error in object file: MARKER token must be followed by an integer > 0. Discarding.\n"); } else { markerIndex--; // Marker numbers are zero-indexed, but in the config file they're 1-indexed. } } // Unknown tokens are ignored. } // Now attempt to load objects. ARLOGd("Reading object data file %s.\n", objectFullpath); objects[i].modelIndex = arOSGLoadModel2(VirtualEnvironment_AROSG, objectFullpath, translation, rotation, scale); if (objects[i].modelIndex < 0) { ARLOGe("Error attempting to read object data file %s.\n", objectFullpath); goto bail4; } // Set optional properties. arOSGSetModelLighting(VirtualEnvironment_AROSG, objects[i].modelIndex, lightingFlag); // If a valid marker index has been specified, save it. if (markerIndex >= 0 /*&& markerIndex < markersCount]*/) { arOSGSetModelVisibility(VirtualEnvironment_AROSG, objects[i].modelIndex, FALSE); // Objects tied to markers will not be initially visible. objects[i].markerIndex = markerIndex; } else { arOSGSetModelVisibility(VirtualEnvironment_AROSG, objects[i].modelIndex, TRUE); // All other objects will be initially visible. objects[i].markerIndex = -1; } objectCount++; } ARLOGd("Virtual Environment initialised.\n"); fclose(fp); return (objectCount); bail4: for (i--; i >= 0; i--) { arOSGUnloadModel(VirtualEnvironment_AROSG, i); } bail3: free(objects); objects = NULL; objectCount = 0; bail2: fclose(fp); bail1: if (VirtualEnvironment_AROSG) { arOSGFinal(VirtualEnvironment_AROSG); VirtualEnvironment_AROSG = NULL; } #ifdef DEBUG ARLOGe("Virtual Environment initialisation failed.\n"); #endif return (0); }
AR2SurfaceSetT *ar2ReadSurfaceSet( const char *filename, const char *ext, ARPattHandle *pattHandle ) { AR2SurfaceSetT *surfaceSet; FILE *fp = NULL; int readMode; char buf[256], name[256]; int i, j, k; if( ext == NULL || *ext == '\0' || strcmp(ext,"fset") == 0 ) { strncpy(name, filename, sizeof(name) - 1); name[sizeof(name) - 1] = '\0'; readMode = 0; } else { char namebuf[512]; sprintf(namebuf, "%s.%s", filename, ext); if ((fp = fopen(namebuf,"r")) == NULL) { ARLOGe("Error opening file '%s': ", filename); ARLOGperror(NULL); return (NULL); } readMode = 1; } arMalloc(surfaceSet, AR2SurfaceSetT, 1); if( readMode ) { if( get_buff(buf, 256, fp) == NULL ) { fclose(fp); free(surfaceSet); return (NULL); } if( sscanf(buf, "%d", &i) != 1 ) { fclose(fp); free(surfaceSet); return (NULL); } if( i < 1 ) { fclose(fp); free(surfaceSet); return (NULL); } surfaceSet->num = i; surfaceSet->contNum = 0; } else { surfaceSet->num = 1; surfaceSet->contNum = 0; } arMalloc(surfaceSet->surface, AR2SurfaceT, surfaceSet->num); for( i = 0; i < surfaceSet->num; i++ ) { ARLOGi("\n### Surface No.%d ###\n", i+1); if( readMode ) { if( get_buff(buf, 256, fp) == NULL ) break; if( sscanf(buf, "%s", name) != 1 ) break; ar2UtilRemoveExt( name ); } ARLOGi(" Read ImageSet.\n"); surfaceSet->surface[i].imageSet = ar2ReadImageSet( name ); if( surfaceSet->surface[i].imageSet == NULL ) { ARLOGe("Error opening file '%s.iset'.\n", name); free(surfaceSet->surface); free(surfaceSet); if (fp) fclose(fp); //COVHI10426 return (NULL); } ARLOGi(" end.\n"); ARLOGi(" Read FeatureSet.\n"); surfaceSet->surface[i].featureSet = ar2ReadFeatureSet( name, "fset" ); if( surfaceSet->surface[i].featureSet == NULL ) { ARLOGe("Error opening file '%s.fset'.\n", name); ar2FreeImageSet(&surfaceSet->surface[i].imageSet); free(surfaceSet->surface); free(surfaceSet); if (fp) fclose(fp); //COVHI10426 return (NULL); } ARLOGi(" end.\n"); if (pattHandle) { ARLOGi(" Read MarkerSet.\n"); ar2UtilRemoveExt( name ); surfaceSet->surface[i].markerSet = ar2ReadMarkerSet( name, "mrk", pattHandle ); if( surfaceSet->surface[i].markerSet == NULL ) { ARLOGe("Error opening file '%s.mrk'.\n", name); ar2FreeFeatureSet(&surfaceSet->surface[i].featureSet); ar2FreeImageSet(&surfaceSet->surface[i].imageSet); free(surfaceSet->surface); free(surfaceSet); if (fp) fclose(fp); //COVHI10426 return (NULL); } ARLOGi(" end.\n"); } else { surfaceSet->surface[i].markerSet = NULL; } if (readMode) { if( get_buff(buf, 256, fp) == NULL ) break; if( sscanf(buf, "%f %f %f %f", &(surfaceSet->surface[i].trans[0][0]), &(surfaceSet->surface[i].trans[0][1]), &(surfaceSet->surface[i].trans[0][2]), &(surfaceSet->surface[i].trans[0][3])) != 4 ) { ARLOGe("Transformation matrix read error!!\n"); fclose(fp); exit(0); } if( get_buff(buf, 256, fp) == NULL ) break; if( sscanf(buf, "%f %f %f %f", &(surfaceSet->surface[i].trans[1][0]), &(surfaceSet->surface[i].trans[1][1]), &(surfaceSet->surface[i].trans[1][2]), &(surfaceSet->surface[i].trans[1][3])) != 4 ) { ARLOGe("Transformation matrix read error!!\n"); fclose(fp); exit(0); } if( get_buff(buf, 256, fp) == NULL ) break; if( sscanf(buf, "%f %f %f %f", &(surfaceSet->surface[i].trans[2][0]), &(surfaceSet->surface[i].trans[2][1]), &(surfaceSet->surface[i].trans[2][2]), &(surfaceSet->surface[i].trans[2][3])) != 4 ) { ARLOGe("Transformation matrix read error!!\n"); fclose(fp); exit(0); } } else { for( j = 0; j < 3; j++ ) { for( k = 0; k < 4; k++ ) { surfaceSet->surface[i].trans[j][k] = (j == k)? 1.0f: 0.0f; } } } arUtilMatInvf( (const float (*)[4])surfaceSet->surface[i].trans, surfaceSet->surface[i].itrans ); ar2UtilReplaceExt( name, 256, "jpg"); arMalloc( surfaceSet->surface[i].jpegName, char, 256); strncpy( surfaceSet->surface[i].jpegName, name, 256 ); } if (fp) fclose(fp); //COVHI10459 if (i < surfaceSet->num) exit(0); return surfaceSet; }
ARMultiMarkerInfoT *arMultiReadConfigFile( const char *filename, ARPattHandle *pattHandle ) { FILE *fp; ARMultiEachMarkerInfoT *marker; ARMultiMarkerInfoT *marker_info; ARdouble wpos3d[4][2]; char buf[256], pattPath[2048], dummy; int num; int patt_type = 0; int i, j; if ((fp = fopen(filename, "r")) == NULL) { ARLOGe("Error: unable to open multimarker config file '%s'.\n", filename); ARLOGperror(NULL); return NULL; } get_buff(buf, 256, fp); if( sscanf(buf, "%d", &num) != 1 ) { ARLOGe("Error processing multimarker config file '%s': First line must be number of marker configs to read.\n", filename); fclose(fp); return NULL; } ARLOGd("Reading %d markers from multimarker file '%s'\n", num, filename); arMalloc(marker, ARMultiEachMarkerInfoT, num); for( i = 0; i < num; i++ ) { get_buff(buf, 256, fp); if (sscanf(buf, #if defined(__LP64__) && !defined(__APPLE__) "%lu%c", #else "%llu%c", #endif &(marker[i].globalID), &dummy) != 1) { // Try first as matrix code. if (!pattHandle) { ARLOGe("Error processing multimarker config file '%s': pattern '%s' specified in multimarker configuration while in barcode-only mode.\n", filename, buf); goto bail; } if (!arUtilGetDirectoryNameFromPath(pattPath, filename, sizeof(pattPath), 1)) { // Get directory prefix. ARLOGe("Error processing multimarker config file '%s': Unable to determine directory name.\n", filename); goto bail; } strncat(pattPath, buf, sizeof(pattPath) - strlen(pattPath) - 1); // Add name of file to open. if ((marker[i].patt_id = arPattLoad(pattHandle, pattPath)) < 0) { ARLOGe("Error processing multimarker config file '%s': Unable to load pattern '%s'.\n", filename, pattPath); goto bail; } marker[i].patt_type = AR_MULTI_PATTERN_TYPE_TEMPLATE; patt_type |= 0x01; } else { if ((marker[i].globalID & 0xffff8000ULL) == 0ULL) marker[i].patt_id = (int)(marker[i].globalID & 0x00007fffULL); // If upper 33 bits are zero, use lower 31 bits as regular matrix code. else marker[i].patt_id = 0; ARLOGd("Marker %3d is matrix code %llu.\n", i + 1, marker[i].globalID); marker[i].patt_type = AR_MULTI_PATTERN_TYPE_MATRIX; patt_type |= 0x02; } get_buff(buf, 256, fp); if( sscanf(buf, #ifdef ARDOUBLE_IS_FLOAT "%f", #else "%lf", #endif &marker[i].width) != 1 ) { ARLOGe("Error processing multimarker config file '%s', marker definition %3d: First line must be pattern width.\n", filename, i + 1); goto bail; } j = 0; get_buff(buf, 256, fp); if( sscanf(buf, #ifdef ARDOUBLE_IS_FLOAT "%f %f %f %f", #else "%lf %lf %lf %lf", #endif &marker[i].trans[j][0], &marker[i].trans[j][1], &marker[i].trans[j][2], &marker[i].trans[j][3]) != 4 ) { // Perhaps this is an old ARToolKit v2.x multimarker file? // If so, then the next line is two values (center) and should be skipped. float t1, t2; if( sscanf(buf, "%f %f", &t1, &t2) != 2 ) { ARLOGe("Error processing multimarker config file '%s', marker definition %3d: Lines 2 - 4 must be marker transform.\n", filename, i + 1); goto bail; } } else j++; do { get_buff(buf, 256, fp); if( sscanf(buf, #ifdef ARDOUBLE_IS_FLOAT "%f %f %f %f", #else "%lf %lf %lf %lf", #endif &marker[i].trans[j][0], &marker[i].trans[j][1], &marker[i].trans[j][2], &marker[i].trans[j][3]) != 4 ) { ARLOGe("Error processing multimarker config file '%s', marker definition %3d: Lines 2 - 4 must be marker transform.\n", filename, i + 1); goto bail; } j++; } while (j < 3); arUtilMatInv( (const ARdouble (*)[4])marker[i].trans, marker[i].itrans ); wpos3d[0][0] = -marker[i].width/2.0; wpos3d[0][1] = marker[i].width/2.0; wpos3d[1][0] = marker[i].width/2.0; wpos3d[1][1] = marker[i].width/2.0; wpos3d[2][0] = marker[i].width/2.0; wpos3d[2][1] = -marker[i].width/2.0; wpos3d[3][0] = -marker[i].width/2.0; wpos3d[3][1] = -marker[i].width/2.0; for( j = 0; j < 4; j++ ) { marker[i].pos3d[j][0] = marker[i].trans[0][0] * wpos3d[j][0] + marker[i].trans[0][1] * wpos3d[j][1] + marker[i].trans[0][3]; marker[i].pos3d[j][1] = marker[i].trans[1][0] * wpos3d[j][0] + marker[i].trans[1][1] * wpos3d[j][1] + marker[i].trans[1][3]; marker[i].pos3d[j][2] = marker[i].trans[2][0] * wpos3d[j][0] + marker[i].trans[2][1] * wpos3d[j][1] + marker[i].trans[2][3]; } } fclose(fp); arMalloc(marker_info, ARMultiMarkerInfoT, 1); marker_info->marker = marker; marker_info->marker_num = num; marker_info->prevF = 0; if( (patt_type & 0x03) == 0x03 ) marker_info->patt_type = AR_MULTI_PATTERN_DETECTION_MODE_TEMPLATE_AND_MATRIX; else if( patt_type & 0x01 ) marker_info->patt_type = AR_MULTI_PATTERN_DETECTION_MODE_TEMPLATE; else marker_info->patt_type = AR_MULTI_PATTERN_DETECTION_MODE_MATRIX; marker_info->cfPattCutoff = AR_MULTI_CONFIDENCE_PATTERN_CUTOFF_DEFAULT; marker_info->cfMatrixCutoff = AR_MULTI_CONFIDENCE_MATRIX_CUTOFF_DEFAULT; return marker_info; bail: fclose(fp); free(marker); return NULL; }
AR_DLL_API ARMultiMarkerInfoT *arMultiReadConfigFile( const char *filename ) { FILE *fp=fopen(filename,"r"); if(fp == NULL){ return NULL; } char buf[256]; get_buff(buf, 256, fp); int num; if( sscanf(buf, "%d", &num) != 1 ) { fclose(fp); return NULL; } ARMultiEachMarkerInfoT *marker; ARMultiMarkerInfoT *marker_info; arMalloc(marker,ARMultiEachMarkerInfoT,num); std::string dir=getdir(filename); for(int i = 0; i < num; i++ ) { get_buff(buf, 256, fp); char buf1[256]; if( sscanf(buf, "%s", buf1) != 1 ) { fclose(fp); free(marker); return NULL; } if( (marker[i].patt_id = arLoadPatt((dir+"/"+buf1).c_str())) < 0 ) { fclose(fp); free(marker); return NULL; } get_buff(buf, 256, fp); if( sscanf(buf, "%lf", &marker[i].width) != 1 ) { fclose(fp); free(marker); return NULL; } get_buff(buf, 256, fp); if( sscanf(buf, "%lf %lf", &marker[i].center[0], &marker[i].center[1]) != 2 ) { fclose(fp); free(marker); return NULL; } for(int j = 0; j < 3; j++ ) { get_buff(buf, 256, fp); if( sscanf(buf, "%lf %lf %lf %lf", &marker[i].trans[j][0], &marker[i].trans[j][1], &marker[i].trans[j][2], &marker[i].trans[j][3]) != 4 ) { fclose(fp); free(marker); return NULL; } } arUtilMatInv( marker[i].trans, marker[i].itrans ); double wpos3d[4][2]; wpos3d[0][0] = marker[i].center[0] - marker[i].width/2.0; wpos3d[0][1] = marker[i].center[1] + marker[i].width/2.0; wpos3d[1][0] = marker[i].center[0] + marker[i].width/2.0; wpos3d[1][1] = marker[i].center[1] + marker[i].width/2.0; wpos3d[2][0] = marker[i].center[0] + marker[i].width/2.0; wpos3d[2][1] = marker[i].center[1] - marker[i].width/2.0; wpos3d[3][0] = marker[i].center[0] - marker[i].width/2.0; wpos3d[3][1] = marker[i].center[1] - marker[i].width/2.0; for(int j = 0; j < 4; j++ ) { marker[i].pos3d[j][0] = marker[i].trans[0][0] * wpos3d[j][0] + marker[i].trans[0][1] * wpos3d[j][1] + marker[i].trans[0][3]; marker[i].pos3d[j][1] = marker[i].trans[1][0] * wpos3d[j][0] + marker[i].trans[1][1] * wpos3d[j][1] + marker[i].trans[1][3]; marker[i].pos3d[j][2] = marker[i].trans[2][0] * wpos3d[j][0] + marker[i].trans[2][1] * wpos3d[j][1] + marker[i].trans[2][3]; } } fclose(fp); marker_info = (ARMultiMarkerInfoT *)malloc( sizeof(ARMultiMarkerInfoT) ); if( marker_info == NULL ) {free(marker); return NULL;} marker_info->marker = marker; marker_info->marker_num = num; marker_info->prevF = 0; return marker_info; }
int client::ls() { const char *tmp[BUFFSIZE] = {0}; if( m_guider.is_at_local() ) { // For local 'ls', it can show more // than one directory. // for(int i = 0; i < m_cmd.size() && i < 10; ++i) { tmp[i] = m_cmd[i]; } // Call the global function ls to show the // information of the specified path in local. if(-1 == ::ls(tmp) ) { return -1; } } else { // For remote 'ls', it can show just // only one directory. // m_buff.clear(); // Add the pack type. m_buff.push_front(PT_LS); // If it has a parameter. if(m_cmd.size() > 1) { // Add the dir-name add_buff(m_cmd[1], strlen(m_cmd[1])); } else { // Show current directory. m_buff.push_back('.'); } // Add the checkcode into the tail of buff. m_analyser.load_data(m_buff); m_buff.push_back(m_analyser.check()); if( -1 == send_data() ) { return -1; } if(-1 == recv_data() ) { return -1; } if( is_pack_type(PT_DATA, m_analyser.get_pack_type()) ) { // Delete the pack type. m_buff.pop_front(); // Print the data. char buff[BUFFSIZE] = {0}; get_buff(buff, BUFFSIZE); cout << buff << endl; } else { ; // Uninterested package. } } return 0; }
ObjectData_T *read_ObjData( char *name, int *objectnum, char *pathtofile ) { FILE *fp; ObjectData_T *object; char buf[256], buf1[256], buf2[256], ptf[256]; int i; post("Opening Data File %s\n",name); if( (fp=fopen(name, "r")) == NULL ) { post("Can't find the file - quitting \n"); return(0); } get_buff(buf, 256, fp); if( sscanf(buf, "%d", objectnum) != 1 ) {fclose(fp); return(0);} post("About to load %d Markers\n",*objectnum); object = (ObjectData_T *)malloc( sizeof(ObjectData_T) * *objectnum ); if( object == NULL ) return(0); for( i = 0; i < *objectnum; i++ ) { memset(&buf2[0], 0, sizeof(buf2)); object[i].visible = 0; get_buff(buf, 256, fp); if( sscanf(buf, "%s", object[i].name) != 1 ) { fclose(fp); free(object); return(0); } post("Marker %s from oulet %d \n", object[i].name, i+1); get_buff(buf, 256, fp); //converted to get the whole line path if( sscanf(buf, "%[^\n]", buf1) != 1 ) { fclose(fp); free(object); return(0); } strcpy(ptf, pathtofile); strcat(ptf, buf1); strcpy(buf2, ptf); if( (object[i].id = arLoadPatt(buf2)) < 0 ){ fclose(fp); free(object); return(0); } get_buff(buf, 256, fp); if( sscanf(buf, "%lf", &object[i].marker_width) != 1 ) { fclose(fp); free(object); return(0); } get_buff(buf, 256, fp); if( sscanf(buf, "%lf %lf", &object[i].marker_center[0], &object[i].marker_center[1]) != 2 ) { fclose(fp); free(object); return(0); } } fclose(fp); return( object ); }
ARMultiMarkerInfoT* Tracker::arMultiReadConfigFile(const char *filename) { FILE *fp; ARMultiEachMarkerInfoT *marker; ARMultiMarkerInfoT *marker_info; ARFloat wpos3d[4][2]; char buf[256], buf1[256]; int num; int i, j; setlocale(LC_NUMERIC, "C"); if ((fp = fopen(filename, "r")) == NULL) return NULL; get_buff(buf, 256, fp); if (sscanf(buf, "%d", &num) != 1) { fclose(fp); return NULL; } arMalloc(marker, ARMultiEachMarkerInfoT, num); for (i = 0; i < num; i++) { get_buff(buf, 256, fp); if (sscanf(buf, "%s", buf1) != 1) { fclose(fp); free(marker); return NULL; } // Added by Daniel: if the markername is an integer number // we directly interprete this as the marker id (used for // id-based markers) if (isNumber(buf1)) marker[i].patt_id = atoi(buf1); else if ((marker[i].patt_id = arLoadPatt(buf1)) < 0) { fclose(fp); free(marker); return NULL; } get_buff(buf, 256, fp); #ifdef _USE_DOUBLE_ if( sscanf(buf, "%lf", &marker[i].width) != 1 ) { #else if (sscanf(buf, "%f", &marker[i].width) != 1) { #endif fclose(fp); free(marker); return NULL; } get_buff(buf, 256, fp); #ifdef _USE_DOUBLE_ if( sscanf(buf, "%lf %lf", &marker[i].center[0], &marker[i].center[1]) != 2 ) { #else if (sscanf(buf, "%f %f", &marker[i].center[0], &marker[i].center[1]) != 2) { #endif fclose(fp); free(marker); return NULL; } for (j = 0; j < 3; j++) { get_buff(buf, 256, fp); if (sscanf(buf, #ifdef _USE_DOUBLE_ "%lf %lf %lf %lf", #else "%f %f %f %f", #endif &marker[i].trans[j][0], &marker[i].trans[j][1], &marker[i].trans[j][2], &marker[i].trans[j][3]) != 4) { fclose(fp); free(marker); return NULL; } } arUtilMatInv(marker[i].trans, marker[i].itrans); wpos3d[0][0] = marker[i].center[0] - marker[i].width * 0.5f; wpos3d[0][1] = marker[i].center[1] + marker[i].width * 0.5f; wpos3d[1][0] = marker[i].center[0] + marker[i].width * 0.5f; wpos3d[1][1] = marker[i].center[1] + marker[i].width * 0.5f; wpos3d[2][0] = marker[i].center[0] + marker[i].width * 0.5f; wpos3d[2][1] = marker[i].center[1] - marker[i].width * 0.5f; wpos3d[3][0] = marker[i].center[0] - marker[i].width * 0.5f; wpos3d[3][1] = marker[i].center[1] - marker[i].width * 0.5f; for (j = 0; j < 4; j++) { marker[i].pos3d[j][0] = marker[i].trans[0][0] * wpos3d[j][0] + marker[i].trans[0][1] * wpos3d[j][1] + marker[i].trans[0][3]; marker[i].pos3d[j][1] = marker[i].trans[1][0] * wpos3d[j][0] + marker[i].trans[1][1] * wpos3d[j][1] + marker[i].trans[1][3]; marker[i].pos3d[j][2] = marker[i].trans[2][0] * wpos3d[j][0] + marker[i].trans[2][1] * wpos3d[j][1] + marker[i].trans[2][3]; } } fclose(fp); setlocale(LC_NUMERIC, "C"); marker_info = (ARMultiMarkerInfoT *) malloc(sizeof(ARMultiMarkerInfoT)); if (marker_info == NULL) { free(marker); return NULL; } marker_info->marker = marker; marker_info->marker_num = num; marker_info->prevF = 0; return marker_info; } } // namespace ARToolKitPlus
int server::ls() { DIR *dp = NULL; struct dirent *entry = NULL; struct stat statbuf = {0}; char buff[BUFFSIZE] = {0}; char oldPath[BUFFSIZE] = {0}; char dir[BUFFSIZE] = {0}; get_buff(dir, BUFFSIZE); //Open the directory to show if(NULL == (dp = opendir(dir))) { printf("ERROR(opendir) '%s': ", dir); fflush(stdout); perror(""); return false; } if(NULL == getcwd(oldPath, BUFFSIZE)) { perror("ERROR(getcwd)"); return false; } //Change current position into specified directory if(-1 == chdir(dir)) { printf("ERROR(chdir) '%s' ", dir); fflush(stdout); perror(""); return false; } //Get next file or dir's entry while((entry = readdir(dp)) != NULL) { //Get the file or directory's stat if(-1 == lstat(entry->d_name, &statbuf)) { printf("ERROR(lstat) '%s' ", entry->d_name); fflush(stdout); perror(""); closedir(dp); return false; } //Filter '.', '..' and '.*' if( '.' == entry->d_name[0] ) { continue; } strcat(buff, entry->d_name); if( S_ISDIR(statbuf.st_mode) ) { strcat(buff, "/"); } else if( statbuf.st_mode & 0111) { strcat(buff, "*"); } strcat(buff, " "); } //Change position into old path if(-1 == chdir(oldPath)) { perror("ERROR(chdir)"); return false; } closedir(dp); // If no file or directory in the path, // add blankspace into buff to translate. if('\0' == buff[0]) { buff[0] = ' '; } // Init the m_buff set_buff(buff, strlen(buff)); bzero(buff, BUFFSIZE); // Add the data size. parse::parse_str(buff, sizeof(short), m_buff.size()); m_buff.insert(m_buff.begin(), buff, buff + sizeof(short)); // Add the pack type. m_buff.push_front(PT_DATA); m_analyser.load_data(m_buff); // Add the pack checkcode. m_buff.push_back(m_analyser.check()); if(-1 == send_data() ) { ; } return 0; }