/* * cleanup -- * Clean up temporary files, show any error messages. */ static int cleanup(int insig) { TAG *intmpp, *missp; ENTRY *ep; int rval = 0; if (insig == 0) { ep = (missp = getlist("_missing")) == NULL ? NULL : TAILQ_FIRST(&missp->list); if (ep != NULL) for (; ep != NULL; ep = TAILQ_NEXT(ep, q)) { if (section) warnx("no entry for %s in " "section %s of the manual.", ep->s, section->s); else warnx("no entry for %s in the manual.", ep->s); rval = 1; } } ep = (intmpp = getlist("_intmp")) == NULL ? NULL : TAILQ_FIRST(&intmpp->list); for (; ep != NULL; ep = TAILQ_NEXT(ep, q)) (void)unlink(ep->s); return (rval); }
/* ARGSUSED */ DBM * mydbm_open (char *file, int flags, int mode) { FILE *fp; DBM *db; fp = CVS_FOPEN (file, (flags & O_ACCMODE) != O_RDONLY ? FOPEN_BINARY_READWRITE : FOPEN_BINARY_READ); if (fp == NULL && !(existence_error (errno) && (flags & O_CREAT))) return NULL; db = xmalloc (sizeof (*db)); db->dbm_list = getlist (); db->modified = 0; db->name = xstrdup (file); if (fp != NULL) { mydbm_load_file (fp, db->dbm_list, file); if (fclose (fp) < 0) error (0, errno, "cannot close %s", primary_root_inverse_translate (file)); } return db; }
int main(int argc, char *argv[]) { int editval = 0; int getval = 0; const char *listfilename; listfilename = ".dlmanagerlist"; if((argv[1]) && strcmp(argv[1], "-") == 0) { listfilename = "usestdin"; } else { editval = edit(listfilename); if(editval == -1) { fprintf(stderr, "\nUnable to open file for edition.\n"); return -1; } } getval = getlist(listfilename); if(getval == -1) { fprintf(stderr, "\nExecution ended with errors\n"); return -1; } fprintf(stdout,"\n"); return 0; }
int main(){ int i; list list; list = initlist(); getlist(list); printlist(list); return 0; }
/* * Clean up when done parsing a function. * All formal parameters, because of a deal (funparm) in * yylex, get put into the symbol table in front of any * global variable of the same name. When the entire * function is parsed, remove these formal dummy nodes * from the symbol table but retain the nodes because * the generated tree points at them. */ void uexit(NODE *np) { NODE *formal; while ((formal = getlist(&np)) != NNULL) delsymtab(formal, 0); }
/*実行*/ int main(void) { int array[MAXELEMENT]; int arraysize = getlist(array); printf("この配列に昇順のクイックソートを適用します。\n"); soating(array,0,arraysize-1); print_list(array,arraysize); return 0; }
// ========================================================================== // METHOD yumsource::getlist // ========================================================================== const value &yumsource::list (void) { value list; value infoargs; string name, summary; list = getlist(); if (! list.count()) { cache = list; return cache; } APP->log (log::info, "yum-src", "Getting descriptions"); infoargs.newval() = "/usr/bin/yum"; infoargs.newval() = "-C"; infoargs.newval() = "info"; infoargs.newval() = "available"; foreach (update, list) { infoargs.newval() = update.id(); } systemprocess infop (infoargs, true); infop.run(); while (! infop.eof()) { string line = infop.gets(); if (line.strlen()) { if (line.strncmp ("Name :", 8) == 0) { line = line.mid (9); name = line; } else if (line.strncmp ("Summary:", 8) == 0) { line = line.mid (9); list[name]["description"] = line; } } } infop.serialize(); resolvealldeps (list); cache = list; cache.saveshox (PATH_CACHEFILE); return cache; }
void root_allow_add (const char *arg, const char *configPath) { Node *n; if (!root_allow) root_allow = getlist(); n = getnode(); n->key = xstrdup (arg); n->data = parse_config (arg, configPath); n->delproc = delconfig; addnode (root_allow, n); }
/* * Add a node to a list allocating the list if necessary. */ static void addlist (List **listp, char *key) { Node *p; if (*listp == NULL) *listp = getlist (); p = getnode (); p->type = FILES; p->key = xstrdup (key); p->data=NULL; if (addnode (*listp, p) != 0) freenode (p); }
/******************************************************************************** PUCK: 函数功能:按编码显示内容:实际C模式显示 入口: type-----模式参数;code-----该模式下显示的项目顺序 返回: ********************************************************************************/ void display(u8 type, code_t code) { vlist.user = code; switch (type) { case modeA: { for (offs_t offs = MODE_A_NUM; offs > 0; --offs) { list_t list = getlist(ITEMMODEA, offs); if (code == list.user) { vlist = list; break; } } break; } case modeB: { for (offs_t offs = MODE_B_NUM; offs > 0; --offs) { list_t list = getlist(ITEMMODEB, offs); if (code == list.user) { vlist = list; break; } } break; } default : { vlist.code = code; vlist.dlen = MAXBITS; break; } } }
// get_width(self, listname) int InvRef::l_get_width(lua_State *L) { NO_MAP_LOCK_REQUIRED; InvRef *ref = checkobject(L, 1); const char *listname = luaL_checkstring(L, 2); InventoryList *list = getlist(L, ref, listname); if(list){ lua_pushinteger(L, list->getWidth()); } else { lua_pushinteger(L, 0); } return 1; }
// is_empty(self, listname) -> true/false int InvRef::l_is_empty(lua_State *L) { NO_MAP_LOCK_REQUIRED; InvRef *ref = checkobject(L, 1); const char *listname = luaL_checkstring(L, 2); InventoryList *list = getlist(L, ref, listname); if(list && list->getUsedSlots() > 0){ lua_pushboolean(L, false); } else { lua_pushboolean(L, true); } return 1; }
// get_stack(self, listname, i) -> itemstack int InvRef::l_get_stack(lua_State *L) { NO_MAP_LOCK_REQUIRED; InvRef *ref = checkobject(L, 1); const char *listname = luaL_checkstring(L, 2); int i = luaL_checknumber(L, 3) - 1; InventoryList *list = getlist(L, ref, listname); ItemStack item; if(list != NULL && i >= 0 && i < (int) list->getSize()) item = list->getItem(i); LuaItemStack::create(L, item); return 1; }
// contains_item(self, listname, itemstack or itemstring or table or nil) -> true/false // Returns true if the list contains the given count of the given item name int InvRef::l_contains_item(lua_State *L) { NO_MAP_LOCK_REQUIRED; InvRef *ref = checkobject(L, 1); const char *listname = luaL_checkstring(L, 2); ItemStack item = read_item(L, 3, getServer(L)->idef()); InventoryList *list = getlist(L, ref, listname); if(list){ lua_pushboolean(L, list->containsItem(item)); } else { lua_pushboolean(L, false); } return 1; }
// room_for_item(self, listname, itemstack or itemstring or table or nil) -> true/false // Returns true if the item completely fits into the list int InvRef::l_room_for_item(lua_State *L) { NO_MAP_LOCK_REQUIRED; InvRef *ref = checkobject(L, 1); const char *listname = luaL_checkstring(L, 2); ItemStack item = read_item(L, 3,STACK_TO_SERVER(L)); InventoryList *list = getlist(L, ref, listname); if(list){ lua_pushboolean(L, list->roomForItem(item)); } else { lua_pushboolean(L, false); } return 1; }
/******************************************************************************** PUCK: 函数功能:按位置显示内容:实际只适用A/B模式 入口: type-----模式参数;offs-----该模式下显示的项目顺序 返回: ********************************************************************************/ void lcdshow (u8 type, offs_t offs) { switch (type) { case modeA: //A模式下,根据645标识及其偏移获取显示元素-----------PUCK { vlist = getlist(ITEMMODEA, offs % MODE_A_NUM); //vlist.dlen = 2; break; } case modeB: //B模式下,根据645标识及其偏移获取显示元素-----------PUCK { vlist = getlist(ITEMMODEB, offs % MODE_B_NUM); //vlist.dlen = 2; break; } default : //C模式下,根据表的偏移获取显示元素-----------PUCK { vlist.user = table[offs % MAXCOUNT].code; vlist.dlen = MAXBITS; break; } } }
/* * append_subdirs -- * Iterate the searchlist and append section and machine * subdirectories as needed. */ static void append_subdirs(TAG *t, const char *machine) { TAG *tsub; ENTRY *eold, *elast, *enew, *esub; char *slashp; eold = elast = TAILQ_FIRST(&t->list); while (eold) { /* * Section subdirectories *not* ending in a slash * only get the machine suffix: They already had * the {cat,man}N part in the configuration file * or got it in parse_path(). */ if (section && eold->s[strlen(eold->s)-1] != '/') { (void)snprintf(gbuf, sizeof(gbuf), "%s{/%s,}", eold->s, machine); free(eold->s); if ((eold->s = strdup(gbuf)) == NULL) err(1, NULL); eold = elast = TAILQ_NEXT(eold, q); continue; } /* * Without a section, expand each entry using the * subdir list, then drop the original entry. */ esub = (tsub = getlist("_subdir")) == NULL ? NULL : TAILQ_FIRST(&tsub->list); while (esub) { slashp = eold->s[strlen(eold->s)-1] == '/' ? "" : "/"; (void)snprintf(gbuf, sizeof(gbuf), "%s%s%s{/%s,}", eold->s, slashp, esub->s, machine); if ((enew = malloc(sizeof(ENTRY))) == NULL || (enew->s = strdup(gbuf)) == NULL) err(1, NULL); TAILQ_INSERT_AFTER(&t->list, elast, enew, q); elast = enew; esub = TAILQ_NEXT(esub, q); } elast = TAILQ_NEXT(elast, q); TAILQ_REMOVE(&t->list, eold, q); eold = elast; } }
// add_item(self, listname, itemstack or itemstring or table or nil) -> itemstack // Returns the leftover stack int InvRef::l_add_item(lua_State *L) { NO_MAP_LOCK_REQUIRED; InvRef *ref = checkobject(L, 1); const char *listname = luaL_checkstring(L, 2); ItemStack item = read_item(L, 3, getServer(L)->idef()); InventoryList *list = getlist(L, ref, listname); if(list){ ItemStack leftover = list->addItem(item); if(leftover.count != item.count) reportInventoryChange(L, ref); LuaItemStack::create(L, leftover); } else { LuaItemStack::create(L, item); } return 1; }
// remove_item(self, listname, itemstack or itemstring or table or nil) -> itemstack // Returns the items that were actually removed int InvRef::l_remove_item(lua_State *L) { NO_MAP_LOCK_REQUIRED; InvRef *ref = checkobject(L, 1); const char *listname = luaL_checkstring(L, 2); ItemStack item = read_item(L, 3, getServer(L)->idef()); InventoryList *list = getlist(L, ref, listname); if(list){ ItemStack removed = list->removeItem(item); if(!removed.empty()) reportInventoryChange(L, ref); LuaItemStack::create(L, removed); } else { LuaItemStack::create(L, ItemStack()); } return 1; }
// set_stack(self, listname, i, stack) -> true/false int InvRef::l_set_stack(lua_State *L) { NO_MAP_LOCK_REQUIRED; InvRef *ref = checkobject(L, 1); const char *listname = luaL_checkstring(L, 2); int i = luaL_checknumber(L, 3) - 1; ItemStack newitem = read_item(L, 4, getServer(L)->idef()); InventoryList *list = getlist(L, ref, listname); if(list != NULL && i >= 0 && i < (int) list->getSize()){ list->changeItem(i, newitem); reportInventoryChange(L, ref); lua_pushboolean(L, true); } else { lua_pushboolean(L, false); } return 1; }
void send_list(char* ip) { int skt = sbp_connect(ip, CNODE_SERVICE_PORT); u64_t blnum = getlist(); struct sbpfs_head head; char* head_data; int head_data_len; head.data = NULL; head.entry_num = 0; head.title = PROTOCOL; char block_num_s[32]; sprintf(block_num_s, "%lld", blnum); char c_len[32]; sprintf(c_len, "%lld", blnum * 8); char dnodename[38]; sprintf(dnodename, "%s%s", "DNode_", dname); mkent(head,CONTENT_LEN,c_len); mkent(head,USER,dnodename); mkent(head,"BlockNum",block_num_s); if (make_head(&head_data, &head_data_len, &head) == -1) { printf("mkhead failed\n"); free(head_data); return; } if (sbp_send(skt, head_data, head_data_len) < 0) { printf("send head err failed\n"); sbp_perror("a"); perror("a"); free(head_data); return; } if (sbp_send(skt, (char*) blolist, bnum * 8) < 0) { printf("send head err failed\n"); sbp_perror("a"); perror("a"); free(head_data); return; } printf("sendlist succeed\n"); if (get_reply(skt) < 0) { printf("error sendlist \n"); return; } printf("reply succeed\n"); }
void variable_set (char *nameval) { char *p; char *name; Node *node; p = nameval; while (isalnum ((unsigned char) *p) || *p == '_') ++p; if (*p != '=') error (1, 0, "invalid character in user variable name in %s", nameval); if (p == nameval) error (1, 0, "empty user variable name in %s", nameval); name = xmalloc (p - nameval + 1); strncpy (name, nameval, p - nameval); name[p - nameval] = '\0'; /* Make p point to the value. */ ++p; if (strchr (p, '\012')) error (1, 0, "linefeed in user variable value in %s", nameval); if (!variable_list) variable_list = getlist (); node = findnode (variable_list, name); if (!node) { node = getnode (); node->type = VARIABLE; node->delproc = variable_delproc; node->key = name; node->data = xstrdup (p); (void) addnode (variable_list, node); } else { /* Replace the old value. For example, this means that -s options on the command line override ones from .cvsrc. */ free (node->data); node->data = xstrdup (p); free (name); } }
LISP getlist () /* чтение списка ВЫР ('.' СПИС | ВЫР)... */ { LISP p = cons (getexpr (), NIL); switch (getlex ()) { case '.': setcdr (p, getexpr ()); break; case ')': ungetlex (); break; default: ungetlex (); setcdr (p, getlist ()); break; case 0: fatal ("unexpected eof"); } return (p); }
int reportlist(char* ip, int port) { if (getlist() < 0) { perror("fail to get list \n"); return -1; } s64_t sockfd = ConnectServer(ip, port); sbphead = report_head(databuf, req_len); build_headp(&send_buf, &sbphead); sendinfo(sockfd, send_buf, sizeof(send_buf)); recinfo(sockfd); if (strcmp(rec_buf, "SBPFS_OK") == 0) { printf("succeed in report"); return 0; } else if (strcmp(rec_buf, "SBPFS_ERR") == 0) { printf("fail in report"); return -1; } else { perror("fail to receive feedback \n"); return -1; } }
void initlist() { int i; char buf[64]; if(access(BLOCKLISTPATH,0)==0) { printf("a\n"); getlist(); return; } memset(buf,0, 64); //strcpy(buf, "0000"); FILE *fd = fopen(BLOCKLISTPATH, "wb+"); for (i = 0; i < 6401; i++) { fwrite(buf, 64, 1, fd); } fclose(fd); }
int main() { FILE *fp=fopen("dir2process.lst","r"); FILE *fp1=fopen("new-files-found.lst","w"); int size = 0; char *list=getlist(fp, &size),*buf; FILE *ptr; char *tmp1 = (char *) malloc (sizeof (char) * size); if ((ptr = popen(("ls -l %s",list), "r")) != NULL) { while (fgets(buf,50,ptr) != NULL) fprintf(fp1, "%s", buf); pclose(ptr); } fclose(fp); fclose(fp1); return 0; }
int get_next_line(int const fd, char **line) { t_listgnl *list; char buf[BUFF_SIZE + 1]; int ret; list = getlist(fd); if (list->nbl == 0) { list->tab = (char *)malloc(sizeof(char) * 1); while ((ret = read(list->fd, buf, BUFF_SIZE)) && ret != -1) { buf[ret] = '\0'; list->tab = ft_malstrcat(list->tab, buf, ret, ret); } if (list->fd < 0 || line == NULL || ret == (-1)) return (-1); list->nbl = 1; } ft_malcpy(line, list); if (line[0][0] == '\0' && list->tab[0] == '\0') return (0); return (1); }
// ========================================================================== // METHOD updatesource::list // ========================================================================== const value &updatesource::list (void) { value list; value outargs; list = getlist (); foreach (update, list) { if (cache.exists (update.id())) { update = cache[update.id()]; } else { update["description"] = getdesc (update.id()); resolvedeps (update.id(), list); } } cache = list; cache.saveshox (PATH_CACHEFILE); return cache; }
/* Create a multi-source buffer. This could easily be generalized to support * any number of source buffers, but for now only two are necessary. */ struct buffer * ms_buffer_initialize (void (*memory) (struct buffer *), struct buffer *buf, struct buffer *buf2/*, ...*/) { struct ms_buffer *mb = xmalloc (sizeof *mb); struct buffer *retbuf; Node *p; mb->block = false; mb->cur = buf; set_nonblock (buf); mb->bufs = getlist (); p = getnode (); p->data = buf2; p->delproc = delbuflist; addnode (mb->bufs, p); retbuf = buf_initialize (ms_buffer_input, NULL, NULL, ms_buffer_block, ms_buffer_get_fd, ms_buffer_shutdown, memory, mb); if (!buf_empty_p (buf)) buf_append_buffer (retbuf, buf); mb->buf = retbuf; return retbuf; }
int open_direct(char *ptype, PRINTER *pp) { short bufsz = -1, cps = -1; int open_mode, fd; register unsigned int oldalarm, newalarm = 0; char *device; struct ecpp_transfer_parms ecpp_params; /* for ECPP port checking */ char **modules = NULL; struct flock lck; struct stat buf; register void (*oldsig)() = signal(SIGALRM, sigalrm); /* * Set an alarm to wake us from trying to open the port. * We'll try at least 60 seconds, or more if the printer * has a huge buffer that, in the worst case, would take * a long time to drain. */ tidbit(ptype, "bufsz", &bufsz); tidbit(ptype, "cps", &cps); if (bufsz > 0 && cps > 0) newalarm = (((long)bufsz * 1100) / cps) / 1000; if (newalarm < 60) newalarm = 60; oldalarm = alarm(newalarm); device = pp->device; if (is_printer_uri(device) == 0) { /* * if it's a device uri and the endpoint contains a valid * path, that path should be opened/locked by lpsched for * the backend. If not, the uri isn't associated with a * local device, so use /dev/null. */ device = strstr(device, "://"); if (device != NULL) device = strchr(device + 3, '/'); if ((device == NULL) || (access(device, F_OK) < 0)) device = "/dev/null"; } /* * The following open must be interruptable. * O_APPEND is set in case the ``port'' is a file. * O_RDWR is set in case the interface program wants * to get input from the printer. Don't fail, though, * just because we can't get read access. */ open_mode = O_WRONLY; if (access(device, R_OK) == 0) open_mode = O_RDWR; open_mode |= O_APPEND; SigAlrm = 0; while ((fd = open(device, open_mode, 0)) == -1) { if (errno != EINTR) return (EXEC_EXIT_NPORT); else if (SigAlrm) return (EXEC_EXIT_TMOUT); } alarm(oldalarm); signal(SIGALRM, oldsig); /* * Lock the file in case two "printers" are defined on the * same port. Don't lock /dev/null. */ lck.l_type = F_WRLCK; lck.l_whence = 0; lck.l_start = 0L; lck.l_len = 0L; if (strcmp(device, "/dev/null") && Fcntl(fd, F_SETLKW, &lck) < 0) { execlog("lock error: %s\n", pp->device); return (EXEC_EXIT_NPORT); } /* * We should get the correct channel number (1), but just * in case.... */ if (fd != 1) { dup2(fd, 1); Close(fd); } /* * Handle streams modules: */ if (fstat(1, &buf)) buf.st_mode = 0; /* * for some unknown reason, lpsched appears to pop the streams * modules off the device and push back some "default" ones, * unless a specific set were specified with the printer configuration. * This behaviour causes problems with the ECPP port, so if we have * an ECPP port, and nobody specified a set of modules to use, we * should leave it alone. Normally, we would not bother to play with * the streams modules, but it is possible that someone has come * to rely on this behaviour for other devices. */ if ((pp->modules != NULL) && (pp->modules[0] != NULL) && (strcmp(pp->modules[0], "default") != 0)) modules = pp->modules; if ((modules == NULL) && (ioctl(1, ECPPIOC_GETPARMS, &ecpp_params) < 0)) modules = getlist(DEFMODULES, LP_WS, LP_SEP); /* if "nopush" is supplied, leave the modules alone */ if ((modules != NULL) && (modules[0] != NULL) && (strcasecmp(modules[0], "nopush") == 0)) modules = NULL; /* * If we have a stream and a list of modules to use, then pop the old * modules and push the new ones. */ if ((modules != NULL) && !S_ISFIFO(buf.st_mode) && isastream(1)) { /* * First, pop all current modules off, unless * instructed not to. */ while (ioctl(1, I_POP, 0) == 0) ; /* * Now push either the administrator specified modules * or the standard modules, unless instructed to push * nothing. */ if ((modules[1] == NULL) && (strcasecmp(modules[0], "none") == 0)) return (0); while (*modules) if (push_module(1, device, *modules++) == -1) return (EXEC_EXIT_NPUSH); } return (0); }