void parseHttp() { String line = Serial.readStringUntil('\n'); if (line.startsWith("Content-Length: ")) { sscanf(line.c_str() + 16, "%d", &contentLength); } else if (line.startsWith("GET")) { method = GET; path = parsePath(line); } else if (line.startsWith("PUT")) { method = PUT; path = parsePath(line); } else if (line == "\r") { if (path.startsWith("/reset")) { sendResponse(200); setup(); } else if (path.startsWith("/sensors") && method == GET) { getSensors(); } else if (path.startsWith("/leds") && (method == GET)) { getLeds(); } else if (path.startsWith("/leds") && (method == PUT)) { putLeds(); } else if (path.startsWith("/settings") && (method == GET)) { getSettings(); } else if (path.startsWith("/settings") && (method == PUT)) { putSettings(); } else { sendResponse(404); } contentLength = 0; } }
/* rename - rename a file or directory * Errors - path resolution, ENOENT, EINVAL, EEXIST * * ENOENT - source does not exist * EEXIST - destination already exists * EINVAL - source and destination are not in the same directory * * Note that this is a simplified version of the UNIX rename * functionality - see 'man 2 rename' for full semantics. In * particular, the full version can move across directories, replace a * destination file, and replace an empty directory with a full one. */ static int hw4_rename(const char *src_path, const char *dst_path) { char *sub_src_path = (char*)calloc(16*44,sizeof(char)); char *sub_dst_path = (char*)calloc(16*44,sizeof(char)); char path1[20][44]; char path2[20][44]; int k = 0; strcpy(sub_src_path, src_path); strcpy(sub_dst_path, dst_path); // save src path to path1 // save dst path to path2 while(1) { sub_src_path = strwrd(sub_src_path, path1[k], 44, " /"); sub_dst_path = strwrd(sub_dst_path, path2[k], 44, " /"); if (sub_src_path == NULL && sub_dst_path == NULL) break; if (sub_src_path == NULL || sub_dst_path == NULL) return -EINVAL; if (strcmp(path1[k], path2[k]) != 0) return -EINVAL; k++; } char *filename = (char*)malloc(sizeof(char)*44); strcpy(filename, path2[k]); int blk_num = super->root_dirent.start; int current_blk_num; // find the block and entry number of the src path int entry = parsePath((void*)src_path, blk_num); current_blk_num = new_current_blk_num; // find the entry number of the dst path int dst_entry = lookupEntry(filename, current_blk_num); // check if the dst file is existed if (dst_entry != -1) return -EEXIST; strcpy(directory[entry].name, filename); directory[entry].mtime = time(NULL); // write back disk->ops->write(disk, current_blk_num*2, 2, (void*)directory); free(filename); free(sub_src_path); free(sub_dst_path); return 0; }
void SvgFlattener::unRotateChild(QDomElement & element, QMatrix transform) { // TODO: missing ellipse element if(!element.hasChildNodes()) { double scale = qMin(qAbs(transform.m11()), qAbs(transform.m22())); if (scale != 1 && transform.m21() == 0 && transform.m12() == 0) { QString sw = element.attribute("stroke-width"); if (!sw.isEmpty()) { bool ok; double strokeWidth = sw.toDouble(&ok); if (ok) { element.setAttribute("stroke-width", QString::number(strokeWidth * scale)); } } } // I'm a leaf node. QString tag = element.nodeName().toLower(); if(tag == "path"){ QString data = element.attribute("d").trimmed(); if (!data.isEmpty()) { const char * slot = SLOT(rotateCommandSlot(QChar, bool, QList<double> &, void *)); PathUserData pathUserData; pathUserData.transform = transform; if (parsePath(data, slot, pathUserData, this, true)) { element.setAttribute("d", pathUserData.string); } } }
/* rmdir - remove a directory * Errors - path resolution, ENOENT, ENOTDIR, ENOTEMPTY */ static int hw4_rmdir(const char *path) { int blk_num = super->root_dirent.start; int current_blk_num; int i; int entry = parsePath((void*)path, blk_num); blk_num = new_blk_num; current_blk_num = new_current_blk_num; // check if it is a directory or not if(directory[entry].isDir == 0) return -ENOTDIR; // check if the directory is empty disk->ops->read(disk, blk_num * 2, 2, (void*)directory); for(i = 0; i < 16; i++) if(directory[i].valid) return -ENOTEMPTY; disk->ops->read(disk, current_blk_num * 2, 2, (void*)directory); directory[entry].valid = 0; fat[blk_num].inUse = 0; // write the changes back disk->ops->write(disk, current_blk_num * 2, 2, (void*)directory); disk->ops->write(disk,2,8,(void*)fat); return 0; }
// open a directory DIR_ITER* EFS_DirOpen(struct _reent *r, DIR_ITER *dirState, const char *path) { EFS_DirStruct *dir = (EFS_DirStruct*)dirState->dirStruct; if(useDLDI && !nds_file) return NULL; // search for the directory in NitroFS filematch = false; searchmode = EFS_SEARCHDIR; file_idpos = ~1; file_idsize = 0; // parse given path parsePath(path, fileInNDS, true); // are we trying to list the root path? if(!strcmp(fileInNDS, "/")) file_idpos = EFS_NITROROOTID; else ExtractDirectory("/", EFS_NITROROOTID); if(file_idpos != ~1) { dir->dir_id = file_idpos; dir->curr_file_id = file_idsize; dir->pos = ~1; return dirState; } return NULL; }
static void * fifo_output_init(G_GNUC_UNUSED const struct audio_format *audio_format, const struct config_param *param, GError **error) { struct fifo_data *fd; char *value, *path; value = config_dup_block_string(param, "path", NULL); if (value == NULL) { g_set_error(error, fifo_output_quark(), errno, "No \"path\" parameter specified"); return NULL; } path = parsePath(value); g_free(value); if (!path) { g_set_error(error, fifo_output_quark(), errno, "Could not parse \"path\" parameter"); return NULL; } fd = fifo_data_new(); fd->path = path; if (!fifo_open(fd, error)) { fifo_data_free(fd); return NULL; } return fd; }
// open a file int EFS_Open(struct _reent *r, void *fileStruct, const char *path, int flags, int mode) { EFS_FileStruct *file = (EFS_FileStruct*)fileStruct; if(useDLDI && !nds_file) return -1; // search for the file in NitroFS filematch = false; searchmode = EFS_SEARCHFILE; file_idpos = 0; file_idsize = 0; // parse given path parsePath(path, fileInNDS, false); // search into NitroFS ExtractDirectory("/", EFS_NITROROOTID); if(file_idpos) { file->start = file_idpos; file->pos = file_idpos; file->end = file_idpos + file_idsize; return 0; } return -1; }
static usize_t ln(String* args) { String not_found = newstr("File not found", 16); // get src file String path = newstr(args->str, args->size); if (path.size == 0) { putraw("Source? ", 8); get(&path); } File* src = fopen(path); if (src == NULL) { println(not_found); return 1; } // get destination path & name putraw("Target? ", 8); String link_name; get(&path); // reusing previously consumed `path` Dir* parent; parsePath(&path, &link_name); parent = open_dir(&path, cwd); if (parent == NULL) { println(not_found); return 1; } return new_file(&link_name, src, parent, t_LINK); }
int main(int argc, char * argv[]) { assert(argc == 3); int fd = open(argv[1], O_RDWR); assert(fd >= 0); char ** fileNames = parsePath(argv[2]); // Super * super = Super_(fd); GroupDesc * groupDesc = Bgd_(fd); // char buf[BLOCK_SIZE]; // for (int i = 0; i < 5; i++) { // int ino = ialloc(fd); // printf("allocated ino = %d\n", ino); // } // printBitmap(fd, (int) super->s_inodes_count, // (int) groupDesc->bg_inode_bitmap); // printBitmap(fd, (int) super->s_blocks_count, // (int) groupDesc->bg_block_bitmap); Inode * target = groupSearch(fd, fileNames, groupDesc); if (target == NULL) { printf("main: unable to find "); printArray(fileNames); } else { inodeShow(fd, target); } close(fd); return EXIT_SUCCESS; }
void SvgFlattener::unRotateChild(QDomElement & element, QMatrix transform) { // TODO: missing ellipse element if(!element.hasChildNodes()) { QString sw = element.attribute("stroke-width"); if (!sw.isEmpty()) { bool ok; double strokeWidth = sw.toDouble(&ok); if (ok) { QLineF line(0, 0, strokeWidth, 0); QLineF newLine = transform.map(line); element.setAttribute("stroke-width", newLine.length()); } } // I'm a leaf node. QString tag = element.nodeName().toLower(); if(tag == "path"){ QString data = element.attribute("d").trimmed(); if (!data.isEmpty()) { const char * slot = SLOT(rotateCommandSlot(QChar, bool, QList<double> &, void *)); PathUserData pathUserData; pathUserData.transform = transform; if (parsePath(data, slot, pathUserData, this, true)) { element.setAttribute("d", pathUserData.string); } } }
void Resty::prep(const string &method, const string &path, MethodHandler f) { string mpath = path; vector<string> names; mRequestMap[method].push_back(parsePath(mpath, f) ); }
///------------------------------------------------------------- bool CCommandLineParser::parseArgv( const char *const argv[ ] ) ///------------------------------------------------------------- { return parsePath( argv ) && parseAmount( argv ) && parseMp3FileName( argv ); }
result_t Url::parse(exlib::string url, bool parseQueryString, bool slashesDenoteHost) { bool bHost; clear(); m_slashes = false; trimUrl(url, url); const char* c_str = url.c_str(); bool hasHash = qstrchr(c_str, '#') != NULL; if (!slashesDenoteHost && !hasHash && isUrlSlash(*c_str)) { parsePath(c_str); parseQuery(c_str); parseHash(c_str); if (parseQueryString) { m_queryParsed = new HttpCollection(); m_queryParsed->parse(m_query); } return 0; } parseProtocol(c_str); bHost = checkHost(c_str); if (slashesDenoteHost || m_protocol.length() > 0 || bHost) m_slashes = ((isUrlSlash(*c_str) && isUrlSlash(c_str[1])) && (m_protocol.length() <= 0 || m_protocol.compare("javascript:"))); if (m_protocol.compare("javascript:") && m_slashes) { c_str += 2; parseAuth(c_str); parseHost(c_str); } parsePath(c_str); parseQuery(c_str); parseHash(c_str); if (parseQueryString) { m_queryParsed = new HttpCollection(); m_queryParsed->parse(m_query); } return 0; }
String URI::getPathFile() const { String dir, base, ext; parsePath(mPath, dir, base, ext); String pathFile = base; if ( !ext.empty() ) pathFile += "." + ext; return pathFile; }
void SvgFileSplitter::painterPathChild(QDomElement & element, QPainterPath & ppath) { // only partially implemented if (element.nodeName().compare("circle") == 0) { double cx = element.attribute("cx").toDouble(); double cy = element.attribute("cy").toDouble(); double r = element.attribute("r").toDouble(); double stroke = element.attribute("stroke-width").toDouble(); ppath.addEllipse(QRectF(cx - r - (stroke / 2), cy - r - (stroke / 2), (r * 2) + stroke, (r * 2) + stroke)); } else if (element.nodeName().compare("line") == 0) { /* double x1 = element.attribute("x1").toDouble(); double y1 = element.attribute("y1").toDouble(); double x2 = element.attribute("x2").toDouble(); double y2 = element.attribute("y2").toDouble(); double stroke = element.attribute("stroke-width").toDouble(); // treat as parallel lines stroke width apart? */ } else if (element.nodeName().compare("rect") == 0) { double width = element.attribute("width").toDouble(); double height = element.attribute("height").toDouble(); double x = element.attribute("x").toDouble(); double y = element.attribute("y").toDouble(); double stroke = element.attribute("stroke-width").toDouble(); double rx = element.attribute("rx").toDouble(); double ry = element.attribute("ry").toDouble(); if (rx != 0 || ry != 0) { ppath.addRoundedRect(x - (stroke / 2), y - (stroke / 2), width + stroke, height + stroke, rx, ry); } else { ppath.addRect(x - (stroke / 2), y - (stroke / 2), width + stroke, height + stroke); } } else if (element.nodeName().compare("ellipse") == 0) { double cx = element.attribute("cx").toDouble(); double cy = element.attribute("cy").toDouble(); double rx = element.attribute("rx").toDouble(); double ry = element.attribute("ry").toDouble(); double stroke = element.attribute("stroke-width").toDouble(); ppath.addEllipse(QRectF(cx - rx - (stroke / 2), cy - ry - (stroke / 2), (rx * 2) + stroke, (ry * 2) + stroke)); } else if (element.nodeName().compare("polygon") == 0 || element.nodeName().compare("polyline") == 0) { QString data = element.attribute("points"); if (!data.isEmpty()) { const char * slot = SLOT(painterPathCommandSlot(QChar, bool, QList<double> &, void *)); PathUserData pathUserData; pathUserData.pathStarting = true; pathUserData.painterPath = &ppath; if (parsePath(data, slot, pathUserData, this, false)) { } } }
void URL_Resolver::parseBase(string base){ getScheme(base); if(schemeIsWeb){ getNET_LOC(base); } parsePath(base); StringUtil::ToLower(SCHEME); StringUtil::ToLower(NET_LOC); }
// change current directory int EFS_ChDir(struct _reent *r, const char *name) { if(!name) return -1; // parse given path parsePath(name, currPath, true); return 0; }
Path::Path(std::string path, std::string file, bool lastIsFolder) { #ifdef NIX m_absolutePath = (path.size() > 0 && path[0] == '/'); #endif parsePath(path, lastIsFolder); if (lastIsFolder == false) m_File = File(file); }
int main(int argc, char *argv[]) { int i; int pid, numChildren; int status; FILE *fid; char cmdLine[MAX_LINE_LEN]; struct command_t command; char *pathv[] = (char *) malloc(MAX_LINE_LEN); parsePath(pathv); /* Get directory paths from PATH */ /* Read the command line parameters */ if ( argc != 2) { fprintf(stderr, "Usage: launch <launch_set_filename>\n"); exit (0); } /* Open a file that contains a set of commands */ fid = fopen(argv[1], "r"); /* Process each command in the launch file */ numChildren = 0; while(fgets(cmdLine, MAX_LINE_LEN, fid) != NULL) { parseCommand(cmdLine, &command); command.argv[command.argc] = NULL; /* Create a child process to execute the command */ if((pid = fork()) == 0) { /* Child executing command */ //execvp(command.name, command.argv); // must use execv instead if(command.name[0] == '/') { execv(command.name, command.argv); } else { execv(lookupPath(*pathv, command.argv), command.argv); } } /* Parent continuing to the next command in the file */ numChildren++; } printf("\n\nlaunch: Launched %d commands\n", numChildren); /* Terminate after all children have terminated */ for(i = 0; i < numChildren; i++) { wait(&status); /* Should free dynamic storage in command data structure */ } printf("\n\nlaunch: Terminating successfully\n"); return 0; }
static void getPathsFromFile(struct pfCompile *pfc, char *fileName) /* Read in several fields of pfc from file. */ { struct hash *hash = raReadSingle(fileName); char *libPath; pfc->cfgHash = hash; pfc->cIncludeDir = mustFindSetting(hash, "cIncludeDir", fileName); pfc->runtimeLib = mustFindSetting(hash, "runtimeLib", fileName); pfc->jkwebLib = mustFindSetting(hash, "jkwebLib", fileName); libPath = mustFindSetting(hash, "paraLibPath", fileName); pfc->paraLibPath = parsePath(libPath); }
static int hw4_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { int len = strlen(path); int i; struct stat sb; memset(&sb, 0, sizeof(sb)); int start = super->root_dirent.start; // find the block number of the path int entry = parsePath((void*)path, start); if(entry == -1) return -ENOENT; start = new_blk_num; disk->ops->read(disk, start * 2, 2, (void*)directory); while(1) { if(!fat[start].inUse) return 0; for(i = 0; i < 16; i++) { if (!directory[i].valid) continue; sb.st_dev = 0; sb.st_ino = 0; sb.st_rdev = 0; sb.st_blocks = directory[i].length / 1024+1; sb.st_blksize = 1024; sb.st_uid = directory[i].uid; sb.st_gid = directory[i].gid; sb.st_size = directory[i].length; sb.st_mtime = sb.st_atime= sb.st_ctime = directory[i].mtime; sb.st_nlink=1; if (len == 1) sb.st_mode = directory[i].mode | S_IFDIR; else sb.st_mode = directory[entry].mode | (directory[entry].isDir ? S_IFDIR : S_IFREG); strcpy(name, directory[i].name); filler(buf, name, &sb,0); } if (fat[start].eof) return 0; start = fat[start].next; disk->ops->read(disk, start * 2, 2, (void*)directory); } return 0; }
static Uri parseUri(char const* str) { Uri uri; auto scheme = parseScheme(str); auto authority = parseAuthority(scheme.ch); auto path = parsePath(authority.ch); uri.schemeIs(scheme.value); uri.authorityIs(authority.value); uri.pathIs(path.value); return uri; }
struct dirNode* checkValidPath(FileDescriptor *fd,struct dirNode* root,int *flag) { int l,exitStatus; struct dirNode *parent; char temp_path[MAX_FULL_PATH_SIZE]; char *path_part; path_part==(char*)malloc(sizeof(MAX_FULL_PATH_SIZE)); strcpy(temp_path,fd->fullPath); path_part=parsePath(temp_path); if(root==NULL) { if(strcmp(path_part,"/")!=0) //for root path *flag=101; //wrong path trying to insert at root } else { exitStatus=FALSE; parent=root; while(exitStatus==FALSE) { if(strstr(path_part,parent->fileDesc->fullPath)==NULL) { if(parent->rightSibling==NULL) { if(strncmp(path_part,parent->fileDesc->fullPath,strlen(path_part)-1)!=0){ *flag=PATH_NOT_FOUND; } exitStatus=TRUE; } else parent=parent->rightSibling; } else { if(parent->firstChild==NULL) { if(strncmp(path_part,parent->fileDesc->fullPath,strlen(path_part)-1)!=0){ *flag=PATH_NOT_FOUND; } exitStatus=TRUE; } else { parent=parent->firstChild; } } } } return root; }
static usize_t mkdir(String* args) { String path = {args->str, args->size}; if (path.str[path.size - 1] == '/') { path.size -= 1; // valid but not useful } String dir_name; Dir* parent; parsePath(&path, &dir_name); parent = open_dir(&path, cwd); if (parent == NULL) { return 1; } return new_file(&dir_name, NULL, parent, t_DIR); }
int main(int argc, char **argv) { if(argc != 3) { fprintf(stderr, "Usage: readimg <image file name> absolute path <ex. /dir1/dir2/>\n"); exit(1); } char * tokens[MAX_TOKENS]; struct comp_inode_type comp_i_t; struct comp_inode_type *comp_it_p = &comp_i_t; parsePath(argv[2], tokens); comp_i_t.inode=0; comp_i_t.file_type=0; loadImage(argv[1]); comp_it_p = getObjectInode(tokens, comp_it_p); if(comp_it_p->inode == 0){ // directory not found! fprintf( stderr, strerror(ENOENT)); fprintf( stderr, "\n"); exit(1); } // directory found! We list its entries int numOfBlocks = pn[comp_it_p->inode -1].i_blocks/SECTORS_PER_LB; int i; for (i=0; i< numOfBlocks; i++){ struct ext2_dir_entry_2 * dblock_p = (struct ext2_dir_entry_2 *)(disk + (pn[comp_it_p->inode - 1].i_block[i]*EXT2_BLOCK_SIZE)); int offset = 0; while(offset < EXT2_BLOCK_SIZE){ printf("%.*s\n", dblock_p->name_len ,dblock_p->name); offset += dblock_p->rec_len; dblock_p = (struct ext2_dir_entry_2 *) (disk + (pn[comp_it_p->inode - 1].i_block[i]*EXT2_BLOCK_SIZE) + offset); } } return 0; }
/** * Transform a XML document given by path. * The stylesheet is retrieved by a processing instruction, * or an error is returned. */ nsresult txStandaloneXSLTProcessor::transform(nsACString& aXMLPath, ostream& aOut, ErrorObserver& aErr) { txXPathNode* xmlDoc = parsePath(aXMLPath, aErr); if (!xmlDoc) { return NS_ERROR_FAILURE; } // transform nsresult rv = transform(*xmlDoc, aOut, aErr); delete xmlDoc; return rv; }
void URI::parsePathEtc(std::string::const_iterator& it, const std::string::const_iterator& end) { if (it == end) return; if (*it != '?' && *it != '#') parsePath(it, end); if (it != end && *it == '?') { ++it; parseQuery(it, end); } if (it != end && *it == '#') { ++it; parseFragment(it, end); } }
int hw4_utime(const char *path, struct utimbuf *ut) { int blk_num = super->root_dirent.start; // find the block and entry number of the path int entry = parsePath((void*)path, blk_num); blk_num = new_current_blk_num; // change the time directory[entry].mtime = time(NULL); // write back disk->ops->write(disk, blk_num * 2, 2, (void*)directory); return 0; }
static int hw4_chmod(const char *path, mode_t mode) { int blk_num = super->root_dirent.start; int entry = parsePath((char*)path, blk_num); blk_num = new_current_blk_num; // update the mode directory[entry].mode = mode; directory[entry].mtime = time(NULL); // write back disk->ops->write(disk, blk_num * 2, 2, (void*)directory); return 0; }
void CPathDescriptor::Serialize(CArchive &ar) { if (ar.IsStoring()) { CString s = getFullPath(); ar << s; ar << (int)m_bEnabled; } else { CString s; ar >> s; this->operator=(s); ar >> m_bEnabled; parsePath(); } }