extern bool bookmark_import(const char *filename) { int fd; dword hash; p_bookmark bm = NULL; if (!filename) return false; fd = xrIoOpen(filename, PSP_O_RDONLY, 0777); if (fd < 0) return false; if (xrIoRead(fd, &hash, sizeof(dword)) < sizeof(dword)) { xrIoClose(fd); return false; } if ((bm = bookmark_open_hash(hash)) == NULL) { xrIoClose(fd); return false; } memset(bm->row, 0xFF, 10 * sizeof(dword)); xrIoRead(fd, &bm->row[0], 10 * sizeof(dword)); bookmark_save(bm); bookmark_close(bm); xrIoClose(fd); return true; }
static void set_type(void *opaque, const char *str) { bookmark_t *bm = opaque; service_set_type(bm->bm_service, str); bookmark_save(); }
/* alias and password should be set already in url */ static void create_the_bookmark(url_t *url) { listitem *li; /* we don't want to be asked again */ url_setalias(ftp->url, url->alias); if(strcmp(ftp->curdir, ftp->homedir) != 0) url_setdirectory(url, ftp->curdir); else url_setdirectory(url, 0); list_clear(gvBookmarks); { char *tmp = NULL; if (asprintf(&tmp, "%s/bookmarks", gvWorkingDirectory) == -1) { fprintf(stderr, _("Failed to allocate memory.\n")); return; } parse_rc(tmp, false); free(tmp); } li = list_search(gvBookmarks, (listsearchfunc)urlcmp, url); if(li) list_delitem(gvBookmarks, li); list_additem(gvBookmarks, url); bookmark_save(0); }
static void bookmark_destroyed(void *opaque, prop_event_t event, ...) { bookmark_t *bm = opaque; prop_sub_t *s; va_list ap; va_start(ap, event); if(event != PROP_DESTROYED) return; s = va_arg(ap, prop_sub_t *); prop_unsubscribe(bm->bm_title_sub); prop_unsubscribe(bm->bm_url_sub); prop_unsubscribe(bm->bm_type_sub); service_destroy(bm->bm_service); free(bm); bookmark_save(); prop_unsubscribe(s); }
void cmd_bookmark(int argc, char **argv) { struct option longopts[] = { {"save", optional_argument, 0, 's'}, {"edit", no_argument, 0, 'e'}, {"read", optional_argument, 0, 'r'}, {"delete", no_argument, 0, 'd'}, {"list", no_argument, 0, 'l'}, {"noupdate", no_argument, 0, 'u'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0} }; int action = BM_BOOKMARK; int c; char *bmfile = 0; optind = 0; while((c=getopt_long(argc, argv, "s::er::dluh", longopts, 0)) != EOF) { switch(c) { case 's': action = BM_SAVE; free(bmfile); bmfile = xstrdup(optarg); break; case 'e': action = BM_EDIT; break; case 'r': action = BM_READ; free(bmfile); bmfile = xstrdup(optarg); break; case 'd': action = BM_DELETE; break; case 'l': action = BM_LIST; break; case 'u': action = BM_TOGGLE_NOUPDATE; break; case 'h': print_bookmark_syntax(); /* fall through */ default: return; } } if(action == BM_SAVE) { bookmark_save(bmfile); if(bmfile) printf(_("bookmarks saved in %s\n"), bmfile); else printf(_("bookmarks saved in %s/bookmarks\n"), gvWorkingDirectory); return; } if(action == BM_READ) { char *tmp = 0; int ret; list_clear(gvBookmarks); if(bmfile) ret = parse_rc(bmfile, true); else { if (asprintf(&tmp, "%s/bookmarks", gvWorkingDirectory) == -1) { fprintf(stderr, _("Failed to allocate memory.\n")); return; } ret = parse_rc(tmp, false); } if(ret != -1) printf(_("bookmarks read from %s\n"), bmfile ? bmfile : tmp); free(tmp); return; } if(action == BM_EDIT) { invoke_shell("%s %s/bookmarks", gvEditor, gvWorkingDirectory); return; } if(action == BM_LIST) { listitem *li; printf(_("%zu bookmarks present in memory\n"), list_numitem(gvBookmarks)); for(li = gvBookmarks->first; li; li=li->next) { url_t *u = (url_t *)li->data; /* note: all info not printed */ printf("%-20s", u->alias ? u->alias : u->hostname); printf("%s://%s@%s", u->protocol ? u->protocol : "ftp", u->username, u->hostname); if(u->directory) { char* sp = shortpath(u->directory, 30, 0); printf("/%s", sp); free(sp); } putchar('\n'); } return; } if(action == BM_DELETE) { int i; bool del_done = false; minargs(optind); for(i = optind; i < argc; i++) { listitem *li; while((li = list_search(gvBookmarks, (listsearchfunc)urlcmp_name, argv[i])) != 0) { url_t *u = (url_t *)li->data; printf(_("deleted bookmark %s\n"), u->alias ? u->alias : u->hostname); list_delitem(gvBookmarks, li); del_done = true; } } if(del_done) { bookmark_save(0); printf(_("bookmarks saved in %s/bookmarks\n"), gvWorkingDirectory); } return; } if(action == BM_TOGGLE_NOUPDATE) { int i; bool toggle_done = false; if(argc == optind) { listitem *li; need_connected(); need_loggedin(); li = list_search(gvBookmarks, (listsearchfunc)urlcmp_name, ftp->url->alias); if(li) { url_t *u = (url_t *)li->data; u->noupdate = !u->noupdate; printf(_("%s: noupdate: %s\n"), u->alias ? u->alias : u->hostname, u->noupdate ? _("yes") : _("no")); toggle_done = true; } ftp->url->noupdate = !ftp->url->noupdate; if(!toggle_done) printf(_("%s: noupdate: %s\n"), ftp->url->alias ? ftp->url->alias : ftp->url->hostname, ftp->url->noupdate ? _("yes") : _("no")); } for(i = optind; i < argc; i++) { listitem *li; li = list_search(gvBookmarks, (listsearchfunc)urlcmp_name, argv[i]); if(li) { url_t *u = (url_t *)li->data; u->noupdate = !u->noupdate; printf(_("%s: noupdate: %s\n"), u->alias ? u->alias : u->hostname, u->noupdate ? _("yes") : _("no")); toggle_done = true; } } if(toggle_done) { bookmark_save(0); printf(_("bookmarks saved in %s/bookmarks\n"), gvWorkingDirectory); } return; } maxargs(1); need_connected(); need_loggedin(); create_bookmark(argc > 1 ? argv[1] : 0); }