/* * m_samode * parv[0] = sender * parv[1] = channel * parv[2] = modes * -t */ DLLFUNC CMD_FUNC(m_samode) { aChannel *chptr; if (!IsPrivileged(cptr) || !IsSAdmin(sptr)) { sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]); return 0; } if (parc > 2) { chptr = find_channel(parv[1], NullChn); if (chptr == NullChn) return 0; } else { sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), me.name, parv[0], "SAMODE"); return 0; } opermode = 0; (void)do_mode(chptr, cptr, sptr, parc - 2, parv + 2, 0, 1); return 0; }
/* ============================================================================= * ud_decode() - Instruction decoder. Returns the number of bytes decoded. * ============================================================================= */ unsigned int ud_decode( struct ud* u ) { inp_start(u); if ( clear_insn( u ) ) { ; /* error */ } else if ( get_prefixes( u ) != 0 ) { ; /* error */ } else if ( search_itab( u ) != 0 ) { ; /* error */ } else if ( do_mode( u ) != 0 ) { ; /* error */ } else if ( disasm_operands( u ) != 0 ) { ; /* error */ } else if ( resolve_mnemonic( u ) != 0 ) { ; /* error */ } /* Handle decode error. */ if ( u->error ) { /* clear out the decode data. */ clear_insn( u ); /* mark the sequence of bytes as invalid. */ u->itab_entry = & ie_invalid; u->mnemonic = u->itab_entry->mnemonic; } u->insn_offset = u->pc; /* set offset of instruction */ u->insn_fill = 0; /* set translation buffer index to 0 */ u->pc += u->inp_ctr; /* move program counter by bytes decoded */ gen_hex( u ); /* generate hex code */ /* return number of bytes disassembled. */ return u->inp_ctr; }
int main() { int lineno = 0; char buf[MAX_LINE]; // input buffer printf("// this code was automatically generated by proccmds.awk\n"); printf("#include \"librcp.h\"\n"); printf("#include <sys/types.h>\n"); printf("#include <sys/stat.h>\n"); printf("#include <unistd.h>\n"); printf("\n"); printf("int module_initialize_commands(CliNode *head) {\n"); printf("\tCliNode *node;\n"); printf("\tCliMode mode = CLIMODE_ALL;\n"); while (fgets(buf, MAX_LINE, stdin) != NULL) { lineno++; char *start = buf; while (*start == ' ' || *start == '\t' || *start == '\n') start++; // empty lines if (*start == '\0') continue; // comments if (*start == '#') continue; // more comments char *ptr = strchr(start, '#'); if (ptr != NULL) *ptr = '\0'; // strip end of string ptr = start + strlen(start); ptr--; while (*ptr == ' ' || *ptr == '\t' || *ptr == '\n') ptr--; ptr++; *ptr = '\0'; // dispatch if (strncmp(start, "M:", 2) == 0) do_mode(start + 2, lineno); else if (strncmp(start, "C:", 2) == 0) do_command(start + 2, lineno); else if (strncmp(start, "Q:", 2) == 0) do_question(start + 2, lineno); else if (strncmp(start, "H:", 2) == 0) do_help(start + 2, lineno); else if (strncmp(start, "S:", 2) == 0) do_script(start + 2, lineno); else { printf("Error: invalid line %d - %s\n", lineno, start); return 1; } } printf("\n\treturn 0;\n"); printf("}\n"); return 0; }
int main (int argc, char **argv) { int i; char *cp; bool greeting; int tmo = 600; progname = ((cp = strrchr(argv[0], '/')) ? cp + 1 : argv[0]); parameters(TRUE); greeting = TRUE; while ((i = opt_get(argc, argv, "t")) > -1) switch (i) { case 'P': log_with_pid(); break; case 'd': debug++; break; case 'V': version(); _exit(0); case 'S': greeting = FALSE; break; case 't': if (!opt_arg) fail(1, "Need value for \"t\""); if ((tmo = strtoul(opt_arg, &cp, 10)) < 0 || *cp) fail(1, "Timeout must be positive"); break; default: usage(); } if (opt_ind < argc) { int pid, lg[2]; if (-1 == (pid = pipefork(lg))) fail(2, "pipe/fork:%m"); if (0 == pid) { if (-1 == dup2(lg[0], 0)) fail(2, "dup:%m"); dup2(1, 2); close(lg[1]); execvp(argv[opt_ind], argv + opt_ind); LOG("exec(%s):%m", argv[opt_ind]); _exit(2); } close(lg[0]); if (-1 == dup2(lg[1], 2)) fail(2, "dup:%m"); } if (-1 == readln_ready(0, tmo, &input)) FAIL(2, "readln_ready:%m"); init(); set_path_var(); if (greeting) { args[1] = "READER"; do_mode(); } /* Main loop */ while (1) { int nr; switch ((nr = args_read(&input))) { case 0: args_write(1, "501 Bad command\r\n"); continue; case -1: do_quit(); /* Does not return */ } if (checkservice) docheckservice(); /* May not return */ for (i = 0; i < sizeof (cmds) / sizeof (struct cmd); i++) { if (strcasecmp(args[0], cmds[i].name)) continue; if (nr < cmds[i].needs_args) args_write(1, "501 Bad syntax\r\n"); else if (cmds[i].needs_group && !currentgroup) args_write(1, "412 No group selected\r\n"); else if (cmds[i].needs_article && -1 == currentserial) args_write(1, "420 No article selected\r\n"); else if (!nr_keys && cmds[i].needs_grouplist && -1 == getallgroups()) args_write(1, "503 No memory\r\n"); else (*cmds[i].function) (); break; } if (i >= sizeof (cmds) / sizeof (struct cmd)) args_write(1, "500 unimplemented\r\n"); } /* Not Reached */ }