/** * Perform the user interface function of editing a program buffer. * @param program The base pointer to the buffer text to edit. * Never returns. */ void CVue::interpret() { if ( !m_running ) { reset(); do_new(); for(;;) { CARIBOU::CString output; show_prompt(); read_line(); if ( compile(output) ) { m_command = output; if (m_command.toInt()) { inherited::reset(); place(); } else { m_running = true; inherited::reset(); do_line(); m_running=false; } } } } inherited::interpret(); }
static void do_new_all(void) { FILE *fp; char *poolname, *type, *arg, *p; int res; fp = fopen(IPPOOL_CONF, "r"); if (!fp) { fprintf(stderr, "cannot open %s - no pool names", IPPOOL_CONF); exit(1); } while (SCAN_EOF != (res=get_index_line(fp, &poolname, &type, &arg))) { if (poolname && type && (0 == strcmp(type, "bitmap"))) { conf_type = IP_POOL_T_BITMAP; p = strtok(arg, " \t"); if (p) { conf_addr = inet_addr(p); p = strtok(0, " \t"); if (p) conf_addr2 = inet_addr(p); else conf_addr = 0; } if (conf_addr != 0) { if (flag_v) printf("ippool -N %s (%s) [%s]\n", poolname, type, arg); do_new(res, 0, 0); } } } fclose(fp); }
int main(int argc, char **argv) { int opt; int op; #define OP_NONE 0 #define OP_LIST 1 #define OP_LIST_ALL 2 #define OP_FLUSH 3 #define OP_FLUSH_ALL 4 #define OP_DESTROY 5 #define OP_DESTROY_ALL 6 #define OP_ADD 7 #define OP_DEL 8 #define OP_CHECK 9 #define OP_NEW 10 #define OP_NEW_ALL 11 #define OP_HIGHEST 12 char *op_pool; fd = socket(AF_INET, SOCK_DGRAM, 0); if (fd < 0) { fprintf(stderr, "cannot get DGRAM socket: %s\n", strerror(errno)); exit(1); } op_pool = 0; op = OP_NONE; /* GRRR. I thought getopt() would allow an "L*" specifier, for an -L * taking an optional argument. Does not work. Bad. * Adding -l for -L without argument, also -f/-F and -x/-X. */ while (EOF != (opt=getopt( argc, argv, "HhnvuqA:D:C:N:t:L:F:X:lfxB"))) switch(opt) { case 'l': if (op != OP_NONE) usage("conflicting operations"); op = OP_LIST_ALL; break; case 'L': if (op != OP_NONE) usage("conflicting operations"); op = OP_LIST; op_pool = optarg; break; case 'f': if (op != OP_NONE) usage("conflicting operations"); op = OP_FLUSH_ALL; break; case 'F': if (op != OP_NONE) usage("conflicting operations"); op = OP_FLUSH; op_pool = optarg; break; case 'x': if (op != OP_NONE) usage("conflicting operations"); op = OP_DESTROY_ALL; break; case 'X': if (op != OP_NONE) usage("conflicting operations"); op = OP_DESTROY; op_pool = optarg; break; case 'A': if (op != OP_NONE) usage("conflicting operations"); op = OP_ADD; op_pool = optarg; break; case 'D': if (op != OP_NONE) usage("conflicting operations"); op = OP_DEL; op_pool = optarg; break; case 'C': if (op != OP_NONE) usage("conflicting operations"); op = OP_CHECK; op_pool = optarg; break; case 'B': if (op != OP_NONE) usage("conflicting operations"); op = OP_NEW_ALL; break; case 'N': if (op != OP_NONE) usage("conflicting operations"); op = OP_NEW; op_pool = optarg; break; case 'H': if (op != OP_NONE) usage("conflicting operations"); op = OP_HIGHEST; break; case 't': flag_t = optarg; break; case 'n': flag_n = 1; break; case 'v': flag_v = 1; break; case 'u': flag_u = 1; break; case 'q': flag_q = 1; break; case 'h': usage(0); default: usage("bad option"); } if (op == OP_NONE) usage("no operation specified"); if (op == OP_LIST_ALL) { do_list_all(); return 0; } if (op == OP_LIST) { do_list(get_index(op_pool)); return 0; } if (op == OP_FLUSH_ALL) { do_flush_all(); return 0; } if (op == OP_FLUSH) { do_flush(get_index(op_pool)); return 0; } if (op == OP_DESTROY_ALL) { do_destroy_all(); return 0; } if (op == OP_DESTROY) { do_destroy(get_index(op_pool)); return 0; } if (op == OP_CHECK) { if (optind >= argc) usage("missing address to check"); return do_check(get_index(op_pool), argv[optind]); } if (op == OP_NEW_ALL) { do_new_all(); return 0; } if (op == OP_NEW) { do_new(get_index(op_pool), argc-optind, argv+optind); return 0; } if (op == OP_ADD) { if (optind >= argc) usage("missing address to add"); return do_adddel(get_index(op_pool), argv[optind], IP_POOL_ADD_ADDR); } if (op == OP_DEL) { if (optind >= argc) usage("missing address to delete"); return do_adddel(get_index(op_pool), argv[optind], IP_POOL_DEL_ADDR); } if (op == OP_HIGHEST) { printf("%d\n", high_nr()); return 0; } usage("no operation specified"); return 0; }
int main(int argc, char *argv[]) { SetDefaultLogging("TEST"); SetNamePgm("test_configurable_lru"); char buf[LENBUF]; int ok = 1; int hrc = 0; int rc = 0; int expected_rc; char c; char *p; int key; LRU_status_t status = 0; LRU_list_t *plru; LRU_parameter_t param; param.nb_entry_prealloc = PREALLOC; param.entry_to_str = print_entry; param.clean_entry = clean_entry; param.name = "Test"; BuddyInit(NULL); if((plru = LRU_Init(param, &status)) == NULL) { LogTest("Test ECHOUE : Mauvaise init"); exit(1); } /* * * La syntaxe d'un test est * 'i key rc' : invalide l'entree avec la clef key * 'n key rc' : cree une nouvelle entree avec la clef key * 'g key rc' : passage du garbage collector (key ne sert a rien) * 'p key rc' : imprime le LRU (key et rc ne servent a rien). * * Une ligne qui debute par '#' est un commentaire * Une ligne qui debute par un espace ou un tab est une ligne vide [meme si il y a des trucs derriere.. :-( ] * Une ligne vide (juste un CR) est une ligne vide (cette citation a recu le Premier Prix lors du Festival International * de la Tautologie de Langue Francaise (FITLF), a Poully le Marais, en Aout 2004) * */ LogTest("============ Debut de l'interactif ================="); while(ok) { /* Code interactif, pompe sur le test rbt de Jacques */ fputs("> ", stdout); if((p = fgets(buf, LENBUF, stdin)) == NULL) { LogTest("fin des commandes"); ok = 0; continue; } if((p = strchr(buf, '\n')) != NULL) *p = '\0'; rc = sscanf(buf, "%c %d %d", &c, &key, &expected_rc); if(c == '#') { /* # indique un commentaire */ continue; } else if(c == ' ' || c == '\t' || rc == -1) { /* Cas d'une ligne vide */ if(rc > 1) LogTest("Erreur de syntaxe : mettre un diese au debut d'un commentaire"); continue; } else { if(rc != 3) { LogTest("Erreur de syntaxe : sscanf retourne %d au lieu de 3", rc); continue; } LogTest("---> %c %d %d", c, key, expected_rc); } switch (c) { case 'i': /* set overwrite */ LogTest("invalidate %d --> %d ?", key, expected_rc); hrc = do_invalidate(plru, key); if(hrc != expected_rc) LogTest(">>>> ERREUR: invalidate %d : %d != %d (expected)", key, hrc, expected_rc); else LogTest(">>>> OK invalidate %d", key); break; case 'n': /* test */ LogTest("new %d --> %d ?", key, expected_rc); hrc = do_new(plru, key); if(hrc != expected_rc) LogTest(">>>> ERREUR: new %d : %d != %d (expected)", key, hrc, expected_rc); else LogTest(">>>> OK new %d", key); break; case 'g': /* set no overwrite */ LogTest("gc %d --> %d ?", key, expected_rc); hrc = do_gc(plru); if(hrc != expected_rc) LogTest(">>>> ERREUR: gc %d: %d != %d (expected)", key, hrc, expected_rc); else LogTest(">>>> OK new %d", key); break; case 'p': /* Print */ LRU_Print(plru); break; default: /* syntaxe error */ LogTest("ordre '%c' non-reconnu", c); break; } } LogTest("===================================================="); LogTest("Test reussi : tous les tests sont passes avec succes"); exit(0); return; } /* main */