static int copydir(ino_t *inodes, int n_inodes, struct stat *oldstats, char *oldpath, char *newpath) { DIR *dir; struct dirent *entry; int i, ol = strlen(oldpath), nl = strlen(newpath); struct stat newstats; for (i = n_inodes-1; i >= 0; i--) if (inodes[i] == oldstats->st_ino) { errno = EINVAL; return -1; } if ((mkdir(newpath, user.umask & 0777) < 0 && errno != EEXIST) || lstat(newpath, &newstats) || !(dir = opendir(oldpath))) return -1; inodes = (ino_t *) XTREALLOC(inodes, (n_inodes+1)*sizeof(ino_t)); inodes[n_inodes++] = newstats.st_ino; for(i = 0; (entry = readdir(dir)); i++) if (entry->d_name[0] != '.' || (entry->d_name[1] != '\0' && (entry->d_name[1] != '.' || entry->d_name[2] != '\0'))) { int ol1 = ol, nl1 = nl, l = strlen(entry->d_name); char *oldpath1 = (char *)alloca(ol1+l+2); char *newpath1 = (char *)alloca(nl1+l+2); strcpy(oldpath1, oldpath); strcpy(newpath1, newpath); if (oldpath1[ol1-1] != '/') oldpath1[ol1++] = '/'; if (newpath1[nl1-1] != '/') newpath1[nl1++] = '/'; strcpy(oldpath1+ol1, entry->d_name); strcpy(newpath1+nl1, entry->d_name); if (copy(inodes, n_inodes, oldpath1, newpath1)) { /* take care of recursive errors */ char s[0xff]; sprintf(s, "Error copying %s:", oldpath1); sysError(s); } } inodes = (ino_t *) XTREALLOC(inodes, (n_inodes-1)*sizeof(ino_t)); return closedir(dir); }
void appOnDeskCb(Widget w, XtPointer client_data, XtPointer call_data) { AppWindowRec *aw = (AppWindowRec *) client_data; AppRec *app, newapp; Widget button; int item; XtVaGetValues(aw->form, XmNuserData, (XtPointer) &button, NULL); item = findAppItem(aw, button); app = &aw->apps[item]; if (app->objType == APPLICATION) { newapp.name = XtNewString(app->name); newapp.directory = XtNewString(app->directory); newapp.fname = XtNewString(app->fname); newapp.icon = XtNewString(app->icon); newapp.push_action = XtNewString(app->push_action); newapp.drop_action = XtNewString(app->drop_action); newapp.objType = APPLICATION; newapp.remove_file = False; } else dupObject(aw->shell, &newapp, app); dtIcons = (DTIconRec **) XTREALLOC(dtIcons, (n_dtIcons + 1) * sizeof(DTIconRec *)); dtIcons[n_dtIcons] = createDTIcon(aw->shell, &newapp, -1, -1); displayDTIcon(dtIcons[n_dtIcons++]); if (resources.auto_save) writeDTIcons(True); }
void removeIconProc(XtPointer awp, int conf) { DTIconRec *dticon = (DTIconRec *) awp; int i; dticons_blocked = False; if (conf == YES) { XtDestroyWidget(dticon->shell); freeApplicationResources(&dticon->app); if (dticon->label_mask != None) freePixmap(dticon->label_mask); if (dticon->drop_pixmap != None) freePixmap(dticon->drop_pixmap); for (i=0; i<n_dtIcons; i++) { if (dtIcons[i] == dticon) { dtIcons[i] = dtIcons[--n_dtIcons]; break;; } } XTFREE(dticon); dtIcons = (DTIconRec **) XTREALLOC(dtIcons, n_dtIcons * sizeof(DTIconRec *)); if (resources.auto_save) writeDTIcons(True); } }
void selectBlockCb(Widget w, XEvent *event, String *params, Cardinal *num_params) { FileWindowRec *fw; SelectionRec *sel; int i, first, last, k; if ((fw = findFileWidget(w, &i))) { sel = &fw->selected; if (sel->n_sel == 1) { if ((k = sel->file[0].nr) < i) { first = k + 1; last = i; } else { first = i; last = k - 1; } for (i = first; i <= last; i++) { if ((k = sel->n_sel++) >= sel->n_alloc) sel->file = (FileSpec *) XTREALLOC(sel->file, (sel->n_alloc += 10) * sizeof(FileSpec)); sel->file[k].nr = i; sel->file[k].name = XtNewString(fw->files[i]->name); sel->n_bytes += fw->files[i]->stats.st_size; XtVaSetValues(fw->files[i]->form, XmNborderColor, resources.select_color, NULL); } updateStatus(fw); } } }
void selectAdd(FileWindowRec *fw, String pattern, Boolean replace_sel) { SelectionRec *sel = &fw->selected; FileRec *file; int i, j; Boolean changed = False; if (replace_sel && fw->selected.n_sel) { unselectAll(fw); changed = True; } for (i=0; i < fw->n_files; i++) { if ((replace_sel || getSelNr(fw, i) == -1) && fnmultimatch(pattern, (file = fw->files[i])->name)) { changed = True; if ((j = sel->n_sel++) >= sel->n_alloc) sel->file = (FileSpec *) XTREALLOC(sel->file, (sel->n_alloc += 10) * sizeof(FileSpec)); sel->file[j].nr = i; sel->file[j].name = XtNewString(file->name); sel->n_bytes += file->stats.st_size; XtVaSetValues(file->form, XmNborderColor, resources.select_color, NULL); } } if (changed) updateStatus(fw); XTFREE(pattern); }
void readDTIcons(void) { FILE *fp; AppRec app; char *name, *directory, *fname, *icon, *push_action, *drop_action, *xp, *yp; char s[MAXAPPSTRINGLEN]; int i, p, x, y; XtAppAddActions(app_context, icon_actions, XtNumber(icon_actions)); trans = XtParseTranslationTable(icon_translations); dticons_blocked = False; if (stat(resources.dticon_file, &dticons_stats) || !(fp = fopen(resources.dticon_file, "r"))) { dticons_readable = False; error(getAnyShell(), "Cannot read desktop icons from", resources.dticon_file); return; } dticons_readable = True; for (i=0; (p = parseIcon(fp, &name, &directory, &fname, &icon, &push_action, &drop_action, &xp, &yp)) > 0; i++) { dtIcons = (DTIconRec **) XTREALLOC(dtIcons, (i+1) * sizeof(DTIconRec *)); app.name = XtNewString(strparse(s, name, "\\:")); app.directory = XtNewString(strparse(s, directory, "\\:")); app.fname = XtNewString(strparse(s, fname, "\\:")); app.icon = XtNewString(strparse(s, icon, "\\:")); app.push_action = XtNewString(strparse(s, push_action, "\\:")); app.drop_action = XtNewString(strparse(s, drop_action, "\\:")); app.objType = getObjectType(app.push_action); app.remove_file = False; if ((x = atoi(strparse(s, xp, "\\:"))) < 0) x += winInfo.rootWidth - DTICONWIDTH; if ((y = atoi(strparse(s, yp, "\\:"))) < 0) y += winInfo.rootHeight - DTICONHEIGHT; dtIcons[i] = createDTIcon(getAnyShell(), &app, x, y); dtIcons[i]->save = True; displayDTIcon(dtIcons[i]); } if (p == -1) error(getAnyShell(), "Error reading desktop icons from", resources.dticon_file); n_dtIcons = i; if (fclose(fp)) sysError(getAnyShell(), "Error reading desktop icons:"); }
char *fnSubA(char *fn) { register int i; int l = strlen(user.home); if (user.home) for (i=0; fn[i]; i++) if (fn[i] == '~') { fn = XTREALLOC(fn, (strlen(fn) + l + 1) * sizeof(char)); strcpy(fn+l, fn+1); memcpy(fn+i, user.home, l); i += l; } return fn; }
int readDirectory(FileList *fl_return, int *n_return, String path) { FileList fl = NULL; DIR *dir; struct dirent *entry; register int n, m; if (chdir(path)) goto error2; if (!(dir = opendir("."))) goto error2; for(n = 0; entry = readdir(dir); n++) { fl = (FileRec **) XTREALLOC(fl, (n+1)*sizeof(FileRec *)); fl[n] = (FileRec *) XtMalloc(sizeof(FileRec)); strcpy(fl[n]->name, entry->d_name); if (lstat(entry->d_name, &(fl[n]->stats))) goto error1; if (S_ISLNK(fl[n]->stats.st_mode)) { fl[n]->sym_link = True; if (stat(entry->d_name, &(fl[n]->stats))) goto error1; } else fl[n]->sym_link = False; fl[n]->selected = False; } if (closedir(dir)) goto error1; *fl_return = fl; *n_return = n; return 0; error1: for(m = 0; m <= n; m++) XTFREE(fl[m]); XTFREE(fl); error2: *fl_return = NULL; *n_return = 0; return -1; }
void readUserObjects(void) { FILE *fp; String atom_name, push_action, label, icon, drag_icon; char s[MAXAPPSTRINGLEN]; int i, p; usrObjects.nr = 0; usrObjects.obj = NULL; if (!(fp = fopen(resources.usrobj_file, "r"))) { if (exists(resources.usrobj_file)) error(topShell, "Cannot read object file", resources.usrobj_file); return; } for (i=0; (p = parseObj(fp, &atom_name, &push_action, &label, &icon, &drag_icon)) > 0; i++) { usrObjects.obj = (UserObjectRec *) XTREALLOC(usrObjects.obj, (i+1) * sizeof(UserObjectRec)); usrObjects.obj[i].atom_name = XtNewString(strparse(s, atom_name, "\\:")); if ((usrObjects.obj[i].atom = XmInternAtom(dpy, usrObjects.obj[i].atom_name, False)) == None) { XTFREE(usrObjects.obj[i].atom_name); error(topShell, "Couldn't initialize user defined object", atom_name); i--; } else { usrObjects.obj[i].push_action = XtNewString(strparse(s, push_action, "\\:")); usrObjects.obj[i].label = XtNewString(strparse(s, label, "\\:")); usrObjects.obj[i].icon = XtNewString(strparse(s, icon, "\\:")); usrObjects.obj[i].drag_icon = XtNewString(strparse(s, drag_icon, "\\:")); } } if (p == -1) error(topShell, "Error in objects file:", resources.usrobj_file); usrObjects.nr = i; if (fclose(fp)) sysError(topShell, "Error reading objects file:"); }
void fileOnDeskCb(Widget w, XtPointer client_data, XtPointer call_data) { AppList *appl; AppRec newapp; FileWindowRec *fw = (FileWindowRec *) client_data; appl = applistFromFiles(fw); newapp.name = XtNewString(appl[0]->name); newapp.directory = XtNewString(appl[0]->directory); newapp.fname = XtNewString(appl[0]->fname); newapp.icon = XtNewString(appl[0]->icon); newapp.push_action = appl[0]->push_action; newapp.drop_action = appl[0]->drop_action; newapp.objType = APPLICATION; newapp.remove_file = False; dtIcons = (DTIconRec **) XTREALLOC(dtIcons, (n_dtIcons + 1) * sizeof(DTIconRec *)); dtIcons[n_dtIcons] = createDTIcon(fw->shell, &newapp, -1, -1); displayDTIcon(dtIcons[n_dtIcons++]); if (resources.auto_save) writeDTIcons(True); XTFREE(appl[0]); XTFREE(appl); }
void filterDirectory(FileList *fl_return, int *n_return, FilterType type) { FileList fl = NULL, oldfl = *fl_return; int n = 0, m = 0; for (; m < *n_return; m++) if (S_ISDIR(oldfl[m]->stats.st_mode) && type == Directories || !S_ISDIR(oldfl[m]->stats.st_mode) && type == Files || (type == All && strcmp(oldfl[m]->name,".") && strcmp(oldfl[m]->name,".."))) { fl = (FileList) XTREALLOC(fl, (n+1)*sizeof(FileRec *)); fl[n] = oldfl[m]; n++; } else XTFREE(oldfl[m]); XTFREE(oldfl); *fl_return = fl; *n_return = n; }
void updateIconDisplay(void) { struct stat cur; Boolean reread = False; if (dticons_blocked) return; if (resources.check_application_files) if (dticons_readable) reread = stat(resources.dticon_file, &cur) || cur.st_ctime > dticons_stats.st_ctime || cur.st_mtime > dticons_stats.st_mtime; else reread = !stat(resources.dticon_file, &cur); if (reread) { FILE *fp; AppRec *app; char *name, *directory, *fname, *icon, *push_action, *drop_action, *xp, *yp; char *nname, *ndirectory, *nfname, *nicon, *npush_action, *ndrop_action; char s[MAXAPPSTRINGLEN]; int i, j, p, x, y; zzz(); dticons_readable = !stat(resources.dticon_file, &dticons_stats); if (!(fp = fopen(resources.dticon_file, "r"))) { dticons_readable = False; error(getAnyShell(), "Cannot read desktop icons from", resources.dticon_file); i = 0; goto remove; } /* update existing icons/append new ones */ for (i=0; (p = parseIcon(fp, &name, &directory, &fname, &icon, &push_action, &drop_action, &xp, &yp)) > 0; i++) { if ((x = atoi(strparse(s, xp, "\\:"))) < 0) x += winInfo.rootWidth - DTICONWIDTH; if ((y = atoi(strparse(s, yp, "\\:"))) < 0) y += winInfo.rootHeight - DTICONHEIGHT; nname = XtNewString(strparse(s, name, "\\:")); ndirectory = XtNewString(strparse(s, directory, "\\:")); nfname = XtNewString(strparse(s, fname, "\\:")); nicon = XtNewString(strparse(s, icon, "\\:")); npush_action = XtNewString(strparse(s, push_action, "\\:")); ndrop_action = XtNewString(strparse(s, drop_action, "\\:")); if (i < n_dtIcons) { DTIconRec *dticon = dtIcons[i]; app = &dticon->app; if (!(x != dticon->x || y != dticon->y || strcmp(nname, app->name) || strcmp(ndirectory, app->directory) || strcmp(nfname, app->fname) || strcmp(nicon, app->icon) || strcmp(npush_action, app->push_action) || strcmp(ndrop_action, app->drop_action))) { XTFREE(nname); XTFREE(ndirectory); XTFREE(nfname); XTFREE(nicon); XTFREE(npush_action); XTFREE(ndrop_action); continue; } XtDestroyWidget(dticon->app.form); if (dticon->label_mask != None) freePixmap(dticon->label_mask); if (dticon->drop_pixmap != None) freePixmap(dticon->drop_pixmap); freeApplicationResources(&dticon->app); } else { dtIcons = (DTIconRec **) XTREALLOC(dtIcons, (i+1) * sizeof(DTIconRec *)); dtIcons[i] = (DTIconRec *) XtMalloc(sizeof(DTIconRec)); } app = &dtIcons[i]->app; app->name = nname; app->directory = ndirectory; app->fname = nfname; app->icon = nicon; app->push_action = npush_action; app->drop_action = ndrop_action; app->objType = getObjectType(app->push_action); app->remove_file = False; dtIcons[i]->x = x; dtIcons[i]->y = y; readApplicationIcon(getAnyShell(), app, ERR_POPUP); dtIcons[i]->label_mask = None; dtIcons[i]->drop_pixmap = None; dtIcons[i]->moved = False; dtIcons[i]->save = True; displayDTIcon(dtIcons[i]); } remove: /* remove any remaining icons */ for (j = i; j < n_dtIcons; j++) { DTIconRec *dticon = dtIcons[j]; XtDestroyWidget(dticon->shell); freeApplicationResources(&dticon->app); if (dticon->label_mask != None) freePixmap(dticon->label_mask); if (dticon->drop_pixmap != None) freePixmap(dticon->drop_pixmap); XTFREE(dticon); } if (i < n_dtIcons) dtIcons = (DTIconRec **) XTREALLOC(dtIcons, i * sizeof(DTIconRec *)); n_dtIcons = i; wakeUp(); if (dticons_readable && p == -1) error(getAnyShell(), "Error reading desktop icons from", resources.dticon_file); if (dticons_readable && fclose(fp)) sysError(getAnyShell(), "Error reading desktop icons:"); } }