int main() { printf("input = "); print_tbl(target_tbl, sizeof(target_tbl)); printf("\n"); bubble_sort(target_tbl, sizeof(target_tbl)); printf("input = "); print_tbl(target_tbl, sizeof(target_tbl)); printf("\n"); return 0; }
int main(int argc, char *argv[]) { int mtype, size, c, list = FALSE, limit = -1, deflt = -1; int fd; char *userlist = 0, *user, **users, *p; short status; struct user_priority *ppri_tbl, *ld_priority_file(); extern char *optarg; extern int optind, opterr, optopt, errno; setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) #define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); if(argc == 1) { usage: (void) printf(gettext("usage: \n")); (void) printf(gettext("(assign priority limit to users)\n")); (void) printf(gettext("\tlpusers -q priority -u user-list\n")); (void) printf(gettext( "(assign default priority limit for balance of users)\n")); (void) printf(gettext("\tlpusers -q priority\n")); (void) printf(gettext("(put users back to default priority limit)\n")); (void) printf(gettext("\tlpusers -u user-list\n")); (void) printf(gettext("(assign default priority)\n")); (void) printf(gettext("\tlpusers -d priority\n")); (void) printf(gettext("(examine priority limits, defaults)\n")); (void) printf(gettext("\tlpusers -l\n")); exit(argc == 1); } opterr = 0; /* disable printing of errors by getopt */ while ((c = getopt(argc, argv, "ld:q:u:")) != -1) switch(c) { case 'l': if (list) LP_ERRMSG1(WARNING, E_LP_2MANY, 'l'); list = TRUE; break; case 'd': if (deflt != -1) LP_ERRMSG1(WARNING, E_LP_2MANY, 'd'); deflt = (int)strtol(optarg,&p,10); if (*p || deflt<PRI_MIN || deflt>PRI_MAX) { LP_ERRMSG1(ERROR, E_LP_BADPRI, optarg); exit(1); } break; case 'q': if (limit != -1) LP_ERRMSG1(WARNING, E_LP_2MANY, 'q'); limit = (int)strtol(optarg,&p,10); if (*p || limit<PRI_MIN || limit>PRI_MAX) { LP_ERRMSG1(ERROR, E_LP_BADPRI, optarg); exit(1); } break; case 'u': if (userlist) LP_ERRMSG1(WARNING, E_LP_2MANY, 'u'); userlist = optarg; break; case '?': if (optopt == '?') goto usage; (p = "-X")[1] = optopt; if (strchr("ldqu", optopt)) LP_ERRMSG1(ERROR, E_LP_OPTARG, p); else LP_ERRMSG1(ERROR, E_LP_OPTION, p); exit(1); } if (optind < argc) { LP_ERRMSG1(ERROR, E_LP_EXTRA, argv[optind]); exit(1); } if (((list || deflt != -1) && (limit != -1 || userlist)) || (list && deflt != -1)) { LP_ERRMSG(ERROR, E_LP_OPTCOMB); /* invalid combination of options */ exit(1); } PRIORITY = Lp_Users; /* load existing priorities from file */ if (!(ppri_tbl = ld_priority_file(PRIORITY))) { switch (errno) { case EBADF: LP_ERRMSG1(ERROR, E_LPU_BADFORM, PRIORITY); break; default: LP_ERRMSG2(ERROR, E_LPU_BADFILE, PRIORITY, errno); } exit(1); } if (list) { print_tbl(ppri_tbl); exit (0); } else { if (userlist) { users = getlist(userlist, " \t", ","); if (users) while (user = *users++) { if (del_user(ppri_tbl, user) && (limit == -1)) LP_ERRMSG1(WARNING, E_LPU_NOUSER, user); if (limit != -1) { if (add_user(ppri_tbl, user, limit)) LP_ERRMSG1(WARNING, E_LPU_BADU, user); } } } else if (deflt != -1) ppri_tbl->deflt = deflt; else ppri_tbl->deflt_limit = limit; if ((fd = open_locked(PRIORITY, "w", LPU_MODE)) < 0) { LP_ERRMSG1(ERROR, E_LP_ACCESS, PRIORITY); exit(1); } output_tbl(fd, ppri_tbl); close(fd); } if (mopen()) /* error on mopen == no spooler, exit quietly */ exit(0); (void)putmessage (message, S_LOAD_USER_FILE); if (msend(message)) goto Error; if (mrecv(reply, sizeof(reply)) == -1) goto Error; mtype = getmessage(reply, R_LOAD_USER_FILE, &status); if (mtype != R_LOAD_USER_FILE) { LP_ERRMSG1 (ERROR, E_LP_BADREPLY, mtype); goto NoError; } if (status == 0) goto NoError; Error: LP_ERRMSG (ERROR, E_LPU_NOLOAD); NoError:(void)mclose (); return (0); }
static void print_mdoc_node(MDOC_ARGS) { int child; struct tag *t; struct htmlpair tag; child = 1; t = h->tags.head; bufinit(h); switch (n->type) { case (MDOC_ROOT): child = mdoc_root_pre(m, n, h); break; case (MDOC_TEXT): /* No tables in this mode... */ assert(NULL == h->tblt); /* * Make sure that if we're in a literal mode already * (i.e., within a <PRE>) don't print the newline. */ if (' ' == *n->string && MDOC_LINE & n->flags) if ( ! (HTML_LITERAL & h->flags)) print_otag(h, TAG_BR, 0, NULL); if (MDOC_DELIMC & n->flags) h->flags |= HTML_NOSPACE; print_text(h, n->string); if (MDOC_DELIMO & n->flags) h->flags |= HTML_NOSPACE; return; case (MDOC_EQN): PAIR_CLASS_INIT(&tag, "eqn"); print_otag(h, TAG_SPAN, 1, &tag); print_text(h, n->eqn->data); break; case (MDOC_TBL): /* * This will take care of initialising all of the table * state data for the first table, then tearing it down * for the last one. */ print_tbl(h, n->span); return; default: /* * Close out the current table, if it's open, and unset * the "meta" table state. This will be reopened on the * next table element. */ if (h->tblt) { print_tblclose(h); t = h->tags.head; } assert(NULL == h->tblt); if (mdocs[n->tok].pre && ENDBODY_NOT == n->end) child = (*mdocs[n->tok].pre)(m, n, h); break; } if (HTML_KEEP & h->flags) { if (n->prev && n->prev->line != n->line) { h->flags &= ~HTML_KEEP; h->flags |= HTML_PREKEEP; } else if (NULL == n->prev) { if (n->parent && n->parent->line != n->line) { h->flags &= ~HTML_KEEP; h->flags |= HTML_PREKEEP; } } } if (child && n->child) print_mdoc_nodelist(m, n->child, h); print_stagq(h, t); bufinit(h); switch (n->type) { case (MDOC_ROOT): mdoc_root_post(m, n, h); break; case (MDOC_EQN): break; default: if (mdocs[n->tok].post && ENDBODY_NOT == n->end) (*mdocs[n->tok].post)(m, n, h); break; } }
static void print_mdoc_node(MDOC_ARGS) { int child; struct tag *t; if (n->type == ROFFT_COMMENT || n->flags & NODE_NOPRT) return; child = 1; t = h->tag; n->flags &= ~NODE_ENDED; switch (n->type) { case ROFFT_TEXT: /* No tables in this mode... */ assert(NULL == h->tblt); /* * Make sure that if we're in a literal mode already * (i.e., within a <PRE>) don't print the newline. */ if (*n->string == ' ' && n->flags & NODE_LINE && (h->flags & (HTML_LITERAL | HTML_NONEWLINE)) == 0) print_otag(h, TAG_BR, ""); if (NODE_DELIMC & n->flags) h->flags |= HTML_NOSPACE; print_text(h, n->string); if (NODE_DELIMO & n->flags) h->flags |= HTML_NOSPACE; return; case ROFFT_EQN: print_eqn(h, n->eqn); break; case ROFFT_TBL: /* * This will take care of initialising all of the table * state data for the first table, then tearing it down * for the last one. */ print_tbl(h, n->span); return; default: /* * Close out the current table, if it's open, and unset * the "meta" table state. This will be reopened on the * next table element. */ if (h->tblt != NULL) { print_tblclose(h); t = h->tag; } assert(h->tblt == NULL); if (n->tok < ROFF_MAX) { roff_html_pre(h, n); child = 0; break; } assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX); if (mdocs[n->tok].pre != NULL && (n->end == ENDBODY_NOT || n->child != NULL)) child = (*mdocs[n->tok].pre)(meta, n, h); break; } if (h->flags & HTML_KEEP && n->flags & NODE_LINE) { h->flags &= ~HTML_KEEP; h->flags |= HTML_PREKEEP; } if (child && n->child) print_mdoc_nodelist(meta, n->child, h); print_stagq(h, t); switch (n->type) { case ROFFT_EQN: break; default: if (n->tok < ROFF_MAX || mdocs[n->tok].post == NULL || n->flags & NODE_ENDED) break; (*mdocs[n->tok].post)(meta, n, h); if (n->end != ENDBODY_NOT) n->body->flags |= NODE_ENDED; break; } }
static void print_man_node(MAN_ARGS) { int child; struct tag *t; child = 1; t = h->tags.head; switch (n->type) { case MAN_ROOT: man_root_pre(man, n, mh, h); break; case MAN_TEXT: if ('\0' == *n->string) { print_paragraph(h); return; } if (n->flags & MAN_LINE && (*n->string == ' ' || (n->prev != NULL && mh->fl & MANH_LITERAL && ! (h->flags & HTML_NONEWLINE)))) print_otag(h, TAG_BR, 0, NULL); print_text(h, n->string); return; case MAN_EQN: print_eqn(h, n->eqn); break; case MAN_TBL: /* * This will take care of initialising all of the table * state data for the first table, then tearing it down * for the last one. */ print_tbl(h, n->span); return; default: /* * Close out scope of font prior to opening a macro * scope. */ if (HTMLFONT_NONE != h->metac) { h->metal = h->metac; h->metac = HTMLFONT_NONE; } /* * Close out the current table, if it's open, and unset * the "meta" table state. This will be reopened on the * next table element. */ if (h->tblt) { print_tblclose(h); t = h->tags.head; } if (mans[n->tok].pre) child = (*mans[n->tok].pre)(man, n, mh, h); break; } if (child && n->child) print_man_nodelist(man, n->child, mh, h); /* This will automatically close out any font scope. */ print_stagq(h, t); switch (n->type) { case MAN_ROOT: man_root_post(man, n, mh, h); break; case MAN_EQN: break; default: if (mans[n->tok].post) (*mans[n->tok].post)(man, n, mh, h); break; } }
static void print_mdoc_node(MDOC_ARGS) { int child; struct tag *t; child = 1; t = h->tags.head; n->flags &= ~MDOC_ENDED; switch (n->type) { case MDOC_ROOT: child = mdoc_root_pre(meta, n, h); break; case MDOC_TEXT: /* No tables in this mode... */ assert(NULL == h->tblt); /* * Make sure that if we're in a literal mode already * (i.e., within a <PRE>) don't print the newline. */ if (' ' == *n->string && MDOC_LINE & n->flags) if ( ! (HTML_LITERAL & h->flags)) print_otag(h, TAG_BR, 0, NULL); if (MDOC_DELIMC & n->flags) h->flags |= HTML_NOSPACE; print_text(h, n->string); if (MDOC_DELIMO & n->flags) h->flags |= HTML_NOSPACE; return; case MDOC_EQN: if (n->flags & MDOC_LINE) putchar('\n'); print_eqn(h, n->eqn); break; case MDOC_TBL: /* * This will take care of initialising all of the table * state data for the first table, then tearing it down * for the last one. */ print_tbl(h, n->span); return; default: /* * Close out the current table, if it's open, and unset * the "meta" table state. This will be reopened on the * next table element. */ if (h->tblt != NULL) { print_tblclose(h); t = h->tags.head; } assert(h->tblt == NULL); if (mdocs[n->tok].pre && (n->end == ENDBODY_NOT || n->child)) child = (*mdocs[n->tok].pre)(meta, n, h); break; } if (h->flags & HTML_KEEP && n->flags & MDOC_LINE) { h->flags &= ~HTML_KEEP; h->flags |= HTML_PREKEEP; } if (child && n->child) print_mdoc_nodelist(meta, n->child, h); print_stagq(h, t); switch (n->type) { case MDOC_ROOT: mdoc_root_post(meta, n, h); break; case MDOC_EQN: break; default: if ( ! mdocs[n->tok].post || n->flags & MDOC_ENDED) break; (*mdocs[n->tok].post)(meta, n, h); if (n->end != ENDBODY_NOT) n->body->flags |= MDOC_ENDED; if (n->end == ENDBODY_NOSPACE) h->flags |= HTML_NOSPACE; break; } }
int main(int argc, const char *argv[]) { int fd; int opt_idx; int checked_value; struct stat sb; size_t tbl_size; uint32_t tbl_idx; struct rte_lpm6_tbl_entry *tbl; char *opts_str[] = { "nexthop", "valid", "valid_group", "ext_entry", "depth", "dump", "dumprange", "nonfree", NULL }; if (argc < 4) { print_usage(); return EXIT_FAILURE; } for (opt_idx = 0; opts_str[opt_idx] != NULL; ++opt_idx) { if (strcmp(argv[2], opts_str[opt_idx]) == 0) { break; } } if (opts_str[opt_idx] == NULL) { fprintf(stderr, "invalid filter\n"); print_usage(); return EXIT_FAILURE; } checked_value = atoi(argv[3]); fd = open(argv[1], O_RDONLY); if (fd < 0) { perror("open:"); return EXIT_FAILURE; } if (fstat(fd, &sb) < 0) { perror("fstat:"); return EXIT_FAILURE; } tbl_size = sb.st_size; tbl = mmap(NULL, tbl_size, PROT_READ, MAP_PRIVATE, fd, 0); for (tbl_idx = 0; tbl_idx < tbl_size / sizeof(*tbl); ++tbl_idx) { switch (opt_idx) { case 0: if (tbl[tbl_idx].next_hop == checked_value) print_tbl(tbl[tbl_idx], tbl_idx); break; case 1: if (tbl[tbl_idx].valid == checked_value) print_tbl(tbl[tbl_idx], tbl_idx); break; case 2: if (tbl[tbl_idx].valid_group == checked_value) print_tbl(tbl[tbl_idx], tbl_idx); break; case 3: if (tbl[tbl_idx].ext_entry == checked_value) print_tbl(tbl[tbl_idx], tbl_idx); break; case 4: if (tbl[tbl_idx].depth == checked_value) print_tbl(tbl[tbl_idx], tbl_idx); break; case 5: if (tbl_idx == checked_value) print_tbl(tbl[tbl_idx], tbl_idx); break; case 6: if (tbl_idx / 256 == checked_value) print_tbl(tbl[tbl_idx], tbl_idx); break; case 7: if (*((uint32_t*)&tbl[tbl_idx]) != 0) print_tbl(tbl[tbl_idx], tbl_idx); break; } } return EXIT_SUCCESS; }
static void print_man_node(MAN_ARGS) { int child; struct tag *t; child = 1; t = h->tags.head; switch (n->type) { case (MAN_ROOT): man_root_pre(man, n, mh, h); break; case (MAN_TEXT): /* * If we have a blank line, output a vertical space. * If we have a space as the first character, break * before printing the line's data. */ if ('\0' == *n->string) { print_otag(h, TAG_P, 0, NULL); return; } if (' ' == *n->string && MAN_LINE & n->flags) print_otag(h, TAG_BR, 0, NULL); else if (MANH_LITERAL & mh->fl && n->prev) print_otag(h, TAG_BR, 0, NULL); print_text(h, n->string); return; case (MAN_EQN): print_eqn(h, n->eqn); break; case (MAN_TBL): /* * This will take care of initialising all of the table * state data for the first table, then tearing it down * for the last one. */ print_tbl(h, n->span); return; default: /* * Close out scope of font prior to opening a macro * scope. */ if (HTMLFONT_NONE != h->metac) { h->metal = h->metac; h->metac = HTMLFONT_NONE; } /* * Close out the current table, if it's open, and unset * the "meta" table state. This will be reopened on the * next table element. */ if (h->tblt) { print_tblclose(h); t = h->tags.head; } if (mans[n->tok].pre) child = (*mans[n->tok].pre)(man, n, mh, h); break; } if (child && n->child) print_man_nodelist(man, n->child, mh, h); /* This will automatically close out any font scope. */ print_stagq(h, t); switch (n->type) { case (MAN_ROOT): man_root_post(man, n, mh, h); break; case (MAN_EQN): break; default: if (mans[n->tok].post) (*mans[n->tok].post)(man, n, mh, h); break; } }
static void print_man_node(MAN_ARGS) { static int want_fillmode = MAN_fi; static int save_fillmode; struct tag *t; int child; /* * Handle fill mode switch requests up front, * they would just cause trouble in the subsequent code. */ switch (n->tok) { case MAN_nf: case MAN_EX: want_fillmode = MAN_nf; return; case MAN_fi: case MAN_EE: want_fillmode = MAN_fi; if (fillmode(h, 0) == MAN_fi) print_otag(h, TAG_BR, ""); return; default: break; } /* Set up fill mode for the upcoming node. */ switch (n->type) { case ROFFT_BLOCK: save_fillmode = 0; /* Some block macros suspend or cancel .nf. */ switch (n->tok) { case MAN_TP: /* Tagged paragraphs */ case MAN_IP: /* temporarily disable .nf */ case MAN_HP: /* for the head. */ save_fillmode = want_fillmode; /* FALLTHROUGH */ case MAN_SH: /* Section headers */ case MAN_SS: /* permanently cancel .nf. */ want_fillmode = MAN_fi; /* FALLTHROUGH */ case MAN_PP: /* These have no head. */ case MAN_LP: /* They will simply */ case MAN_P: /* reopen .nf in the body. */ case MAN_RS: case MAN_UR: fillmode(h, MAN_fi); break; default: break; } break; case ROFFT_TBL: fillmode(h, MAN_fi); break; case ROFFT_ELEM: /* * Some in-line macros produce tags and/or text * in the handler, so they require fill mode to be * configured up front just like for text nodes. * For the others, keep the traditional approach * of doing the same, for now. */ fillmode(h, want_fillmode); break; case ROFFT_TEXT: if (fillmode(h, want_fillmode) == MAN_fi && want_fillmode == MAN_fi && n->flags & NODE_LINE && *n->string == ' ' && (h->flags & HTML_NONEWLINE) == 0) print_otag(h, TAG_BR, ""); if (*n->string != '\0') break; print_paragraph(h); return; default: break; } /* Produce output for this node. */ child = 1; switch (n->type) { case ROFFT_TEXT: t = h->tag; print_text(h, n->string); break; case ROFFT_EQN: t = h->tag; print_eqn(h, n->eqn); break; case ROFFT_TBL: /* * This will take care of initialising all of the table * state data for the first table, then tearing it down * for the last one. */ print_tbl(h, n->span); return; default: /* * Close out scope of font prior to opening a macro * scope. */ if (HTMLFONT_NONE != h->metac) { h->metal = h->metac; h->metac = HTMLFONT_NONE; } /* * Close out the current table, if it's open, and unset * the "meta" table state. This will be reopened on the * next table element. */ if (h->tblt) print_tblclose(h); t = h->tag; if (n->tok < ROFF_MAX) { roff_html_pre(h, n); child = 0; break; } assert(n->tok >= MAN_TH && n->tok < MAN_MAX); if (mans[n->tok].pre) child = (*mans[n->tok].pre)(man, n, h); /* Some block macros resume .nf in the body. */ if (save_fillmode && n->type == ROFFT_BODY) want_fillmode = save_fillmode; break; } if (child && n->child) print_man_nodelist(man, n->child, h); /* This will automatically close out any font scope. */ print_stagq(h, t); if (fillmode(h, 0) == MAN_nf && n->next != NULL && n->next->flags & NODE_LINE) print_endline(h); }