sp<Retval> GdMonCpustat::draw(int num, sp<info>& info, sp<MonBase>& dest , const char* path) { sp<Retval> retval; if( DFW_RET(retval, MonCpustat::draw(num, info, dest, path)) ) return DFW_RETVAL_D(retval); if( DFW_RET(retval, baseInit()) ) return DFW_RETVAL_D(retval); struct max_st max; struct data_st dt; getMax(&max, info, m_g.cs.w); setData(&dt); drawHead(dest->m_sec, info->m_sec); uint64_t first_sec; uint64_t last_sec = dest->m_sec; for(int k=info->m_aLists.size(), dx=m_g.cr.ex; ((k>0)&&(dx>m_g.cr.sx));) { sp<GdMonCpustat> p = info->m_aLists.get(k-1); sp<GdMonCpustat> pp = info->m_aLists.get(k-2); procData(dx, &max, &dt, p, pp); drawData(dx, &dt); k--; dx--; first_sec = p->m_sec; } drawBottom(dest, &max, &dt); drawLast(first_sec, last_sec); if( DFW_RET(retval, savePng(path, savename(), 0)) ) return DFW_RETVAL_D(retval); return NULL; }
bool CDocument::saveToFile(const QString &file){ QString savename( m_fileInfo.absoluteFilePath() ); if( file.length() > 0 ) savename = file; else if( !m_fileInfo.exists() ){ savename = QFileDialog::getSaveFileName( 0 , "Save to.." ); } QFile fileq( savename ); if( !fileq.open( QIODevice::WriteOnly ) ){ QMessageBox::critical( 0 , "Save failed!" , "Unable to open the file for save!" ); return false; } QByteArray bit8 = m_editor->toPlainText().toLocal8Bit(); qint64 savedBytes = fileq.write( bit8 ); fileq.close(); if( savedBytes != bit8.size() ){ QMessageBox::critical( 0 , "Save failed!" , "Seem that not all bytes have been written." ); return false; } editor()->document()->setModified( false ); return true; }
/* * add an entry to the symbol table */ struct entry * addentry(char *name, ino_t inum, int type) { struct entry *np, *ep; if (freelist != NULL) { np = freelist; freelist = np->e_next; memset(np, 0, sizeof(struct entry)); } else { np = calloc(1, sizeof(struct entry)); if (np == NULL) panic("no memory to extend symbol table\n"); } np->e_type = type & ~LINK; ep = lookupparent(name); if (ep == NULL) { if (inum != ROOTINO || lookupino(ROOTINO) != NULL) panic("bad name to addentry %s\n", name); np->e_name = savename(name); np->e_namlen = strlen(name); np->e_parent = np; addino(ROOTINO, np); return (np); } np->e_name = savename(strrchr(name, '/') + 1); np->e_namlen = strlen(np->e_name); np->e_parent = ep; np->e_sibling = ep->e_entries; ep->e_entries = np; if (type & LINK) { ep = lookupino(inum); if (ep == NULL) panic("link to non-existent name\n"); np->e_ino = inum; np->e_links = ep->e_links; ep->e_links = np; } else if (inum != 0) { if (lookupino(inum) != NULL) panic("duplicate entry\n"); addino(inum, np); } return (np); }
/* * Read the contents of a directory. */ static void mkentry(const char *name, struct direct *dp, struct afile *fp) { char *cp; struct entry *np; fp->fnum = dp->d_ino; fp->fname = savename(dp->d_name); for (cp = fp->fname; *cp; cp++) if (!vflag && (*cp < ' ' || *cp >= 0177)) *cp = '?'; fp->len = cp - fp->fname; if (dflag && TSTINO(fp->fnum, dumpmap) == 0) fp->prefix = '^'; else if ((np = lookupname(name)) != NULL && (np->e_flags & NEW)) fp->prefix = '*'; else fp->prefix = ' '; switch(dp->d_type) { default: fprintf(stderr, "Warning: undefined file type %d\n", dp->d_type); /* fall through */ case DT_REG: fp->postfix = ' '; break; case DT_LNK: fp->postfix = '@'; break; case DT_FIFO: case DT_SOCK: fp->postfix = '='; break; case DT_CHR: case DT_BLK: fp->postfix = '#'; break; case DT_WHT: fp->postfix = '%'; break; case DT_UNKNOWN: case DT_DIR: if (inodetype(dp->d_ino) == NODE) fp->postfix = '/'; else fp->postfix = ' '; break; } return; }
/* * Change a name to a unique temporary name. */ void mktempname(struct entry *ep) { char oldname[MAXPATHLEN]; if (ep->e_flags & TMPNAME) badentry(ep, "mktempname: called with TMPNAME"); ep->e_flags |= TMPNAME; (void) strcpy(oldname, myname(ep)); freename(ep->e_name); ep->e_name = savename(gentempname(ep)); ep->e_namlen = strlen(ep->e_name); renameit(oldname, myname(ep)); }
static struct subr_desc *subr_install( char *name,void *(*subr)() ) { int val; struct subr_desc *sd=subr_lookup(name); if (sd == NULL) { sd = tcob_malloc( sizeof(struct subr_desc) ); if (sd==NULL) return NULL; if ( (sd->name = savename( name ) ) == NULL ) return NULL; val = subr_hash( sd->name ); sd->next = subrtab[ val ]; sd->subr = subr; subrtab[ val ] = sd; } return sd; }
/* * Relocate an entry in the tree structure */ void moveentry(struct entry *ep, char *newname) { struct entry *np; char *cp; np = lookupparent(newname); if (np == NULL) badentry(ep, "cannot move ROOT"); if (np != ep->e_parent) { removeentry(ep); ep->e_parent = np; ep->e_sibling = np->e_entries; np->e_entries = ep; } cp = strrchr(newname, '/') + 1; freename(ep->e_name); ep->e_name = savename(cp); ep->e_namlen = strlen(cp); if (strcmp(gentempname(ep), ep->e_name) == 0) ep->e_flags |= TMPNAME; else ep->e_flags &= ~TMPNAME; }
/* * Do an "ls" style listing of a directory */ static void printlist(const char *name, char *basename) { struct afile *fp, *list, *listp = NULL; struct direct *dp; struct afile single; RST_DIR *dirp; int entries, len, namelen; char locname[MAXPATHLEN + 1]; dp = pathsearch(name); if (dp == NULL || (!dflag && TSTINO(dp->d_ino, dumpmap) == 0) || (!vflag && dp->d_ino == UFS_WINO)) return; if ((dirp = rst_opendir(name)) == NULL) { entries = 1; list = &single; mkentry(name, dp, list); len = strlen(basename) + 1; if (strlen(name) - len > (unsigned short)single.len) { freename(single.fname); single.fname = savename(&name[len]); single.len = strlen(single.fname); } } else { entries = 0; while ((dp = rst_readdir(dirp))) entries++; rst_closedir(dirp); list = (struct afile *)malloc(entries * sizeof(struct afile)); if (list == NULL) { fprintf(stderr, "ls: out of memory\n"); return; } if ((dirp = rst_opendir(name)) == NULL) panic("directory reopen failed\n"); fprintf(stderr, "%s:\n", name); entries = 0; listp = list; strncpy(locname, name, MAXPATHLEN); strncat(locname, "/", MAXPATHLEN); namelen = strlen(locname); while ((dp = rst_readdir(dirp))) { if (dp == NULL) break; if (!dflag && TSTINO(dp->d_ino, dumpmap) == 0) continue; if (!vflag && (dp->d_ino == UFS_WINO || strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0)) continue; locname[namelen] = '\0'; if (namelen + dp->d_namlen >= MAXPATHLEN) { fprintf(stderr, "%s%s: name exceeds %d char\n", locname, dp->d_name, MAXPATHLEN); } else { strncat(locname, dp->d_name, (int)dp->d_namlen); mkentry(locname, dp, listp++); entries++; } } rst_closedir(dirp); if (entries == 0) { fprintf(stderr, "\n"); free(list); return; } qsort((char *)list, entries, sizeof(struct afile), fcmp); } formatf(list, entries); if (dirp != NULL) { for (fp = listp - 1; fp >= list; fp--) freename(fp->fname); fprintf(stderr, "\n"); free(list); } }