int main(int argc, char *argv[]) { extern char *optarg; extern int optind; extern FILE *dbf; int opt; dbf = fopen("/dev/null", "w"); if (!dbf) dbf = stderr; cgi_setup(WEB_ROOT); while ((opt = getopt(argc, argv,"s:")) != EOF) { switch (opt) { case 's': pstrcpy(servicesf,optarg); break; } } print_header(); charset_initialise(); if (load_config()) { cgi_load_variables(NULL); process_requests(); show_services(); } print_footer(); return 0; }
int main(int argc, const char * argv[]) { /* Mandatory HTML info and navbar, etc. */ init_page("blog"); /* Google analytics script */ include_google_analytics(); /* Print Blog entries */ char *env_string = getenv("QUERY_STRING"); // Get the variables we want from env variable char *start = get_variable(env_string, "start="); char *end = get_variable(env_string, "end="); char *search = get_variable(env_string, "search="); char *month = get_variable(env_string, "month="); char *year = get_variable(env_string, "year="); printf("<div class=\"container\">"); // Start container that holds posts printf("<div class=\"row\"><div class=\"col-sm-8 blog-main\">"); if (search != NULL) { print_search_notification(search); print_blog_posts(0, 10000, search); } else if (month != NULL && year != NULL) { print_posts_by_monthyear(atoi(month), atoi(year)); } else if (start != NULL && end != NULL) { int int_start = atoi(start); int int_end = atoi(end); print_blog_posts(int_start, int_end, NULL); } else { print_blog_posts(0, 4, NULL); } // Free the variables we got free(start); free(end); free(search); printf("</div>"); // Close Blog // Blog sidebar printf("<div class=\"col-sm-3 col-sm-offset-1 blog-sidebar\">"); print_about_box(); print_archives(); printf("</div>"); // Close sidebar printf("</div>"); // Close row printf("</div>"); // Close container printf("</body>"); // End HTML body, is opened in init_page() /* Print page footer, copyright, name, etc. */ print_footer(); printf("</html>"); return 0; }
void view_vcard (int entry_number, vc_component * v) { vc_component *vc = NULL; char *val = NULL; g_v = v; vc = vc_get_next_by_name (g_v, VC_FORMATTED_NAME); val = vc_get_value (vc); print_footer (entry_number, val ? val : ""); switch (g_mode) { case VIEW_IDENT: view_ident (); break; case VIEW_GEO: view_geo (); break; case VIEW_TEL: view_tel (); break; case VIEW_ORG: view_org (); break; case VIEW_MISC: view_misc (); break; default: break; } }
int main (int argc, char *argv[]) { OilFunctionClass *klass; int i; int n; oil_init_no_optimize (); print_header (); n = oil_class_get_n_classes (); for (i=0;i<n; i++ ){ #ifdef __CW32__ klass = (OilFunctionClass*)oil_class_get_by_index (i); printf ("OIL_DECLARE_CLASS(%s);\n", klass->name); #else klass = oil_class_get_by_index (i); printf ("OIL_DECLARE_CLASS(%s);\n", klass->name); #endif } print_footer (); return 0; }
void user_interface( ){ // window dimensions int maxX, maxY, cursor = 0; // iterate until its time to exit while( true ){ // get the window size maxX = getmaxx(stdscr); maxY = getmaxy(stdscr); // clear the screen clear(); // print the header print_header("Task Listing", maxX); // print the table print_table( maxX, maxY, 4 , cursor); // print the footer print_footer( GUI, maxX, maxY ); // get the input int arg = getch(); // exit the program if( arg == 27 ) break; // create a new task else if( arg == 'c' || arg == 'C' ){ create_task( ); } // view the selected task else if( arg == 'V' || arg == 'v' ){ view_task( ); } // move the cursor up else if( arg == KEY_UP ){ cursor--; if( cursor < 0 ){ cursor = options.tasks.size()-1; } } // move the cursor down else if( arg == KEY_DOWN ){ cursor++; if( cursor >= options.tasks.size() ) cursor = 0; } } }
int main() { int ret; print_header(1); ret = gen_page(); print_footer(); return ret; }
void print_graph() { int i; print_header(); for (i = 0; states[i].table1; i++) print_state(&states[i]); print_footer(); }
/*------------------------------------------------------------------------- * Function: main * * Purpose: Main entry point. * * Return: Success: exit(0) * * Failure: exit(1) * * Programmer: Albert Cheng * 2010/4/1 * *------------------------------------------------------------------------- */ int main(void) { print_header(); /* Generate embedded library information variable definition */ make_libinfo(); print_footer(); HDexit(0); }
void DotPrinter::visit(const node::SymbolNodeIFace* _node) { if(m_print_digraph_block && _node->is_root()) print_header(m_horizontal); std::cout << "\t" << _node->uid() << " [" << std::endl << "\t\tlabel=\"" << _node->name() << "\"," << std::endl << "\t\tshape=\"ellipse\"" << std::endl << "\t];" << std::endl; VisitorDFS::visit(_node); if(!_node->is_root()) std::cout << '\t' << _node->parent()->uid() << "->" << _node->uid() << ";" << std::endl; if(m_print_digraph_block && _node->is_root()) print_footer(); }
int main(int argc, char **argv) { FILE *file; char name[MAX_NAME_LENGTH], clan[MAX_NAME_LENGTH]; struct player_array array = PLAYER_ARRAY_ZERO; unsigned i; load_config(); if (argc != 2) { fprintf(stderr, "usage: %s <clan_name>\n", argv[0]); return EXIT_FAILURE; } /* Load players */ sprintf(path, "%s/clans/%s", config.root, argv[1]); if (!(file = fopen(path, "r"))) return perror(path), EXIT_FAILURE; while (fscanf(file, " %s", name) == 1) { struct player player; if (!read_player(&player, name)) strcpy(player.clan, argv[1]); add_player(&array, &player); } fclose(file); /* Sort players */ qsort(array.players, array.length, sizeof(*array.players), cmp_player); /* Eventually, print them */ hex_to_string(argv[1], clan); print_header(&CTF_TAB, clan, NULL); printf("<h2>%s</h2>\n", clan); printf("<p>%u member(s)</p>\n", array.length); printf("<table><thead><tr><th></th><th>Name</th><th>Clan</th><th>Score</th></tr></thead>\n<tbody>\n"); for (i = 0; i < array.length; i++) html_print_player(&array.players[i], 0); printf("</tbody></table>\n"); print_footer(); return EXIT_SUCCESS; }
void print_footer_xfr(const size_t total_len, const size_t msg_count, const size_t rr_count, const net_t *net, const float elapsed, const time_t exec_time, const style_t *style) { if (style == NULL) { DBG_NULL; return; } if (style->show_footer) { print_footer(total_len, msg_count, rr_count, net, elapsed, exec_time, true); } }
int main (int argc, char *argv[]) { OilFunctionClass *klass; OilPrototype *proto; int i; int n; char *string; oil_init_no_optimize (); print_header (); n = oil_class_get_n_classes (); for (i=0;i<n; i++ ){ klass = oil_class_get_by_index (i); if(klass->prototype) { proto = oil_prototype_from_string (klass->prototype); if (proto) { string = oil_prototype_to_string (proto); if (strlen (string) == 0) { free (string); string = xstrdup("void"); } printf ("OIL_EXPORT OilFunctionClass *oil_function_class_ptr_%s;\n", klass->name); printf ("typedef void (*_oil_type_%s)(%s);\n",klass->name,string); printf ("#define oil_%s ((_oil_type_%s)(*(void(**)(void))oil_function_class_ptr_%s))\n", klass->name, klass->name, klass->name); oil_prototype_free (proto); free (string); } else { printf("/* ERROR: could not parse %s(%s) */\n", klass->name, klass->prototype); } } } print_footer (); return 0; }
int main(int argc, char **argv) { load_config(); print_header(&ABOUT_TAB, "About", NULL); puts( "<h1>About</h1>" "<p>Teerank is an <em>unofficial</em> ranking system for <a href=\"https://www.teeworlds.com/\">Teeworlds</a>. It aims to be simple and fast to use. You can find the <a href=\"https://github.com/needs/teerank\">source code on github</a>. Teerank is a free software under <a href=\"http://www.gnu.org/licenses/gpl-3.0.txt\">GNU GPL 3.0</a>.</p>" "<p>Report any bugs or ideas on <a href=\"https://github.com/needs/teerank/issues\">github issue tracker</a> or send them by e-mail at <a href=\"mailto:[email protected]\">[email protected]</a>.</p>" "<h1>Under the hood</h1>" "<p>Teerank works by polling CTF servers every 5 minutes. Based on the score difference between two polls, it compute your score using a custom <a href=\"https://en.wikipedia.org/wiki/Elo_rating_system\">ELO rating system</a>.</p>" "<p>The system as it is cannot know the team you are playing on, it also do not handle any sort of player authentification, thus faking is easy. That's why Teerank should not be taken too seriously, because it is built on a very naïve aproach.</p>" ); print_footer(); return EXIT_SUCCESS; }
int main (int argc, char *argv[]) { printf("Analyzing...\n"); ofp=fopen(o_file_0,"w"); if(ofp==NULL){ fprintf(stderr, "Can't open output file %s!\n", o_file_0); return(1); } /* sections of our gv file */ print_header(); print_body(argc, argv); print_footer(); fclose(ofp); printf("Generated graph.\n"); return 0; }
/*------------------------------------------------------------------------- * Function: main * * Purpose: Main entry point. * * Return: Success: EXIT_SUCCESS *------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { char *fname = NULL; FILE *f; /* temporary holding place for the stream pointer * so that rawoutstream is changed only when succeeded */ if(argc > 1) fname = argv[1]; /* First check if filename is string "NULL" */ if(fname != NULL) { /* binary output */ if((f = HDfopen(fname, "w")) != NULL) rawoutstream = f; } if(!rawoutstream) rawoutstream = stdout; print_header(); /* Generate embedded library information variable definition */ make_libinfo(); print_footer(); if(rawoutstream && rawoutstream != stdout) { if(HDfclose(rawoutstream)) fprintf(stderr, "closing rawoutstream"); else rawoutstream = NULL; } HDexit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { int i; const char *datafile = NULL; const char *inputfile = NULL; const char *ip = NULL; const char *outputfile = NULL; const char *format = "CSV"; const char *field = NULL; int noheading = 0; IP2Location *dbobj = NULL; IP2LocationRecord *record = NULL; FILE *fout = stdout; field = "ip,countryshort,countrylong,region,city,isp,latitude,longitude,domain,zipcode,timezone,netspeed,iddcode,areacode,weatherstationcode,weatherstationname,mcc,mnc,mobilebrand,elevation,usagetype"; for (i = 1; i < argc; i++) { const char *argvi = argv[i]; if (strcmp(argvi, "-d") == 0 || strcmp(argvi, "--datafile") == 0) { if (i + 1 < argc) { datafile = argv[++i]; } } else if (strcmp(argvi, "-i") == 0 || strcmp(argvi, "--inputfile") == 0) { if (i + 1 < argc) { inputfile = argv[++i]; } } else if (strcmp(argvi, "-p") == 0 || strcmp(argvi, "--ip") == 0) { if (i + 1 < argc) { ip = argv[++i]; } } else if (strcmp(argvi, "-o") == 0 || strcmp(argvi, "--outputfile") == 0) { if (i + 1 < argc) { outputfile = argv[++i]; } } else if (strcmp(argvi, "-f") == 0 || strcmp(argvi, "--format") == 0) { if (i + 1 < argc) { format = argv[++i]; } } else if (strcmp(argvi, "-h") == 0 || strcmp(argvi, "-?") == 0 || strcmp(argvi, "--help") == 0) { print_usage(argv[0]); return 0; } else if (strcmp(argvi, "-v") == 0 || strcmp(argvi, "--version") == 0) { print_version(); return 0; } else if (strcmp(argvi, "-e") == 0 || strcmp(argvi, "--field") == 0) { if (i + 1 < argc) { field = argv[++i]; } } else if (strcmp(argvi, "-n") == 0 || strcmp(argvi, "--noheading") == 0) { noheading = 1; } } if (strcmp(format, "CSV") != 0 && strcmp(format, "XML") != 0 && strcmp(format, "TAB") != 0) { fprintf(stderr, "Invalid format %s, supported formats: CSV, XML, TAB\n", format); exit(-1); } if (datafile == NULL) { fprintf(stderr, "Datafile is absent\n"); exit(-1); } if (ip == NULL) { fprintf(stderr, "IP address is absent\n"); exit(-1); } dbobj = IP2Location_open((char *)datafile); if (dbobj == NULL) { fprintf(stderr, "Failed to open datafile %s\n", datafile); exit(-1); } if (outputfile != NULL) { fout = fopen(outputfile, "w"); if (fout == NULL) { fprintf(stderr, "Failed to open outputfile %s\n", outputfile); exit(-1); } } if (!noheading) { print_header(fout, field, format); } if (ip != NULL) { record = IP2Location_get_all(dbobj, (char *)ip); print_record(fout, field, record, format, ip); IP2Location_free_record(record); } if (inputfile != NULL) { char *line = NULL; size_t n; ssize_t len; FILE *fin = fopen(inputfile, "r"); if (fin == NULL) { fprintf(stderr, "Failed to open inputfile %s\n", inputfile); exit(-1); } while ((len = getline(&line, &n, fin)) != -1) { if (line[len - 1] == '\n') { line[--len] = '\0'; } if (line[len - 1] == '\r') { line[--len] = '\0'; } record = IP2Location_get_all(dbobj, line); print_record(fout, field, record, format, line); IP2Location_free_record(record); } fclose(fin); } print_footer(fout, field, format); IP2Location_close(dbobj); // OS will clean-up the rest return 0; }
void print_packet(const knot_pkt_t *packet, const net_t *net, const size_t size, const float elapsed, const time_t exec_time, const bool incoming, const style_t *style) { if (packet == NULL || style == NULL) { DBG_NULL; return; } const knot_pktsection_t *answers = knot_pkt_section(packet, KNOT_ANSWER); const knot_pktsection_t *authority = knot_pkt_section(packet, KNOT_AUTHORITY); const knot_pktsection_t *additional = knot_pkt_section(packet, KNOT_ADDITIONAL); uint16_t qdcount = knot_wire_get_qdcount(packet->wire); uint16_t ancount = knot_wire_get_ancount(packet->wire); uint16_t nscount = knot_wire_get_nscount(packet->wire); uint16_t arcount = knot_wire_get_arcount(packet->wire); // Get Extended RCODE from the packet. uint16_t rcode = knot_pkt_get_ext_rcode(packet); // Disable additionals printing if there are no other records. // OPT record may be placed anywhere within additionals! if (knot_pkt_has_edns(packet) && arcount == 1) { arcount = 0; } // Print packet information header. if (style->show_header) { print_header(packet, style, rcode); } // Print EDNS section. if (style->show_edns && knot_pkt_has_edns(packet)) { printf("\n;; EDNS PSEUDOSECTION:\n;; "); print_section_opt(packet->opt_rr, knot_wire_get_rcode(packet->wire)); } // Print DNS sections. switch (style->format) { case FORMAT_DIG: if (ancount > 0) { print_section_dig(knot_pkt_rr(answers, 0), ancount, style); } break; case FORMAT_HOST: if (ancount > 0) { print_section_host(knot_pkt_rr(answers, 0), ancount, style); } else { print_error_host(rcode, packet, style); } break; case FORMAT_NSUPDATE: if (style->show_question && qdcount > 0) { printf("\n;; ZONE SECTION:\n;; "); print_section_question(knot_pkt_qname(packet), knot_pkt_qclass(packet), knot_pkt_qtype(packet), style); } if (style->show_answer && ancount > 0) { printf("\n;; PREREQUISITE SECTION:\n"); print_section_full(knot_pkt_rr(answers, 0), ancount, style, true); } if (style->show_authority && nscount > 0) { printf("\n;; UPDATE SECTION:\n"); print_section_full(knot_pkt_rr(authority, 0), nscount, style, true); } if (style->show_additional && arcount > 0) { printf("\n;; ADDITIONAL DATA:\n"); print_section_full(knot_pkt_rr(additional, 0), arcount, style, true); } break; case FORMAT_FULL: if (style->show_question && qdcount > 0) { printf("\n;; QUESTION SECTION:\n;; "); print_section_question(knot_pkt_qname(packet), knot_pkt_qclass(packet), knot_pkt_qtype(packet), style); } if (style->show_answer && ancount > 0) { printf("\n;; ANSWER SECTION:\n"); print_section_full(knot_pkt_rr(answers, 0), ancount, style, true); } if (style->show_authority && nscount > 0) { printf("\n;; AUTHORITY SECTION:\n"); print_section_full(knot_pkt_rr(authority, 0), nscount, style, true); } if (style->show_additional && arcount > 0) { printf("\n;; ADDITIONAL SECTION:\n"); print_section_full(knot_pkt_rr(additional, 0), arcount, style, true); } break; default: break; } // Print TSIG section. if (style->show_tsig && knot_pkt_has_tsig(packet)) { printf("\n;; TSIG PSEUDOSECTION:\n"); print_section_full(packet->tsig_rr, 1, style, false); } // Print packet statistics. if (style->show_footer) { printf("\n"); print_footer(size, 0, 0, net, elapsed, exec_time, incoming); } }
void page_break(void) { line_break(); if (current_line) print_footer(); }
void line_break(void) { int *d, ch; int spg = 1, rspg = 1, spgs = 0, gap = 0; if (line_ptr == 0) return; if (current_line == 0) print_header(); if (page_length > 12 && current_line + pending_nl > page_length - 6) { print_footer(); print_header(); } if (current_line) current_line += 1 + pending_nl; for (; pending_nl > 0; pending_nl--) fprintf(ofd, "\n"); if (right_adjust < 0) { int over = right_margin - left_indent - (line_ptr - line); #ifdef SPLATTER fprintf(ofd, ">Gaps=%d, Over=%d, ", gaps_on_line, over); #endif if (gaps_on_line && over) { spg = rspg = 1 + over / gaps_on_line; over = over % gaps_on_line; if (over) { if (current_line % 2) { spgs = over; spg++; } else { spgs = gaps_on_line - over; rspg++; } } } #ifdef SPLATTER fprintf(ofd, " (%d,%d) sw=%d\n", spg, rspg, spgs); #endif right_adjust = 1; } *line_ptr = 0; if (*line) for (ch = left_indent; ch > 0; ch--) fputc(' ', ofd); for (d = line; *d; d++) { ch = *d; if ((ch & 0xFF) == 0) { int i; if (gap++ < spgs) i = spg; else i = rspg; for (; i > 0; i--) fputc(' ', ofd); } else switch (ch >> 8) { case 2: fputc(ch & 0xFF, ofd); fputc('\b', ofd); fputc(ch & 0xFF, ofd); break; case 3: fputc('_', ofd); fputc('\b', ofd); fputc(ch & 0xFF, ofd); break; default: fputc(ch & 0xFF, ofd); break; } } fputc('\n', ofd); line_ptr = 0; if (next_line_indent > 0) left_indent = next_line_indent; next_line_indent = -1; gaps_on_line = 0; }
int main(int argc, char *argv[]) { void *hostwalk, *clonewalk; int argi; char *envarea = NULL; strbuffer_t *outbuf; char msgline[4096]; char oneurl[10240]; int gotany = 0; enum { OP_INITIAL, OP_YES, OP_NO } gotonepage = OP_INITIAL; /* Tracks if all matches are on one page */ char *onepage = NULL; /* If gotonepage==OP_YES, then this is the page */ /*[wm] regex support */ #define BUFSIZE 256 regex_t re; char re_errstr[BUFSIZE]; int re_status; for (argi=1; (argi < argc); argi++) { if (argnmatch(argv[argi], "--env=")) { char *p = strchr(argv[argi], '='); loadenv(p+1, envarea); } else if (argnmatch(argv[argi], "--area=")) { char *p = strchr(argv[argi], '='); envarea = strdup(p+1); } } redirect_cgilog("findhost"); cgidata = cgi_request(); if (cgidata == NULL) { /* Present the query form */ sethostenv("", "", "", colorname(COL_BLUE), NULL); printf("Content-type: %s\n\n", xgetenv("HTMLCONTENTTYPE")); showform(stdout, "findhost", "findhost_form", COL_BLUE, getcurrenttime(NULL), NULL, NULL); return 0; } parse_query(); if ( (re_status = regcomp(&re, pSearchPat, re_flag)) != 0 ) { regerror(re_status, &re, re_errstr, BUFSIZE); print_header(); printf("<tr><td align=left><font color=red>%s</font></td>\n", pSearchPat); printf("<td align=left><font color=red>%s</font></td></tr>\n", re_errstr); print_footer(); return 0; } outbuf = newstrbuffer(0); load_hostnames(xgetenv("HOSTSCFG"), NULL, get_fqdn()); hostwalk = first_host(); while (hostwalk) { /* * [wm] - Allow the search to be done on the hostname * also on the "displayname" and the host comment * Maybe this should be implemented by changing the HTML form, but until than.. * we're supposing that hostname will NEVER be null */ char *hostname, *displayname, *comment, *ip; hostname = xmh_item(hostwalk, XMH_HOSTNAME); displayname = xmh_item(hostwalk, XMH_DISPLAYNAME); comment = xmh_item(hostwalk, XMH_COMMENT); ip = xmh_item(hostwalk, XMH_IP); if ( regexec (&re, hostname, (size_t)0, NULL, 0) == 0 || (regexec(&re, ip, (size_t)0, NULL, 0) == 0) || (displayname && regexec (&re, displayname, (size_t)0, NULL, 0) == 0) || (comment && regexec (&re, comment, (size_t)0, NULL, 0) == 0) ) { /* match */ addtobuffer(outbuf, "<tr>\n"); sprintf(msgline, "<td align=left> %s </td>\n", displayname ? displayname : hostname); addtobuffer(outbuf, msgline); sprintf(oneurl, "%s/%s/#%s", xgetenv("XYMONWEB"), xmh_item(hostwalk, XMH_PAGEPATH), hostname); sprintf(msgline, "<td align=left> <a href=\"%s\">%s</a>\n", oneurl, xmh_item(hostwalk, XMH_PAGEPATHTITLE)); addtobuffer(outbuf, msgline); gotany++; /* See if all of the matches so far are on one page */ switch (gotonepage) { case OP_INITIAL: gotonepage = OP_YES; onepage = xmh_item(hostwalk, XMH_PAGEPATH); break; case OP_YES: if (strcmp(onepage, xmh_item(hostwalk, XMH_PAGEPATH)) != 0) gotonepage = OP_NO; break; case OP_NO: break; } clonewalk = next_host(hostwalk, 1); while (clonewalk && (strcmp(xmh_item(hostwalk, XMH_HOSTNAME), xmh_item(clonewalk, XMH_HOSTNAME)) == 0)) { sprintf(msgline, "<br><a href=\"%s/%s/#%s\">%s</a>\n", xgetenv("XYMONWEB"), xmh_item(clonewalk, XMH_PAGEPATH), xmh_item(clonewalk, XMH_HOSTNAME), xmh_item(clonewalk, XMH_PAGEPATHTITLE)); addtobuffer(outbuf, msgline); clonewalk = next_host(clonewalk, 1); gotany++; } addtobuffer(outbuf, "</td>\n</tr>\n"); hostwalk = clonewalk; } else { hostwalk = next_host(hostwalk, 0); } } regfree (&re); /*[wm] - free regex compiled patern */ if (dojump) { if (gotany == 1) { printf("Location: %s%s\n\n", xgetenv("XYMONWEBHOST"), oneurl); return 0; } else if ((gotany > 1) && (gotonepage == OP_YES)) { printf("Location: %s%s/%s/\n\n", xgetenv("XYMONWEBHOST"), xgetenv("XYMONWEB"), onepage); return 0; } } print_header(); if (!gotany) { printf("<tr><td align=left>%s</td><td align=left>Not found</td></tr>\n", pSearchPat); } else { printf("%s", grabstrbuffer(outbuf)); } print_footer(); /* [wm] - Free the strdup allocated memory */ if (pSearchPat) xfree(pSearchPat); return 0; }
int main(int argc, char *argv[]) { int i = 0; // Loop counter. int ids[NUM_PHILOSOPHERS]; // Initialize the IDs array. for (i = 0; i < NUM_PHILOSOPHERS; i++) { ids[i] = i; } // Retrieve the command-line argument of how many times to cycle. if (argc >= 2) { number_of_times_to_cycle = strtol(argv[1], NULL, 10); } // Print the header in the parent thread. print_header(); // Initialize the global mutex lock. if (pthread_mutex_init(&global_mutex_lock, NULL ) == -1) { fprintf(stderr, "pthread_mutex_init" " failed: %s", strerror(errno)); exit(-1); } // Initialize the Forks. for (i = 0; i < NUM_PHILOSOPHERS; i++) { forks[i].id = i; forks[i].owner = NULL; // Initialize each mutex lock. if (pthread_mutex_init(&forks[i].mutex_lock, NULL ) == -1) { fprintf(stderr, "pthread_mutex_init" " failed: %s", strerror(errno)); exit(-1); } } // Initialize the Philosophers. for (i = 0; i < NUM_PHILOSOPHERS; i++) { phils[i].id = i; phils[i].des_left_fork = ((i + 1) % NUM_PHILOSOPHERS); phils[i].des_right_fork = (i % NUM_PHILOSOPHERS); #if DEBUG printf("Philosopher %c's assigned " "left fork is %d\n", i + 'A', phils[i].des_left_fork); printf("Philosopher %c's assigned " "right fork is %d\n\n", i + 'A', phils[i].des_right_fork); #endif phils[i].state = CHANGING; } // Spawn each of the Philosophers' pthreads. for (i = 0; i < NUM_PHILOSOPHERS; i++) { int res; pthread_t *t = &phils[i].thread; res = pthread_create(t, NULL, cycle, (void *) (&ids[i])); if (res == -1) { fprintf(stderr, "Child %i: " "%s\n", i, strerror(errno)); exit(-1); } } // Now wait for each Philosopher's thread to finish. for (i = 0; i < NUM_PHILOSOPHERS; i++) { int res; res = pthread_join(phils[i].thread, NULL ); if (res == -1) { perror("join"); exit(-1); } } // Print the footer in the parent thread. print_footer(); // Destroy the Forks' mutex locks. for (i = 0; i < NUM_PHILOSOPHERS; i++) { if (pthread_mutex_destroy(&forks[i].mutex_lock) == -1) { fprintf(stderr, "pthread_mutex_init " "failed: %s", strerror(errno)); exit(-1); } } // Destroy the global mutex lock. if (pthread_mutex_init(&global_mutex_lock, NULL ) == -1) { fprintf(stderr, "pthread_mutex_init" " failed: %s", strerror(errno)); exit(-1); } return 0; // Exit successfully. }
int main(void) { struct cks_config *config = NULL; PGconn *conn = NULL; char *method = NULL; char *content = NULL; unsigned long content_length = 0; char *name = NULL; char *val = NULL; char *value = NULL; char *debug_val = NULL; int rslt = 0; int tmp_var = 0; config = (struct cks_config *)malloc(sizeof(struct cks_config)); if(config == NULL) { fprintf(stderr,_("cks_export: Fatal Error: Malloc Call Failed: Out of memroy.\n")); return -1; } rslt = init_config(&config); if(rslt == -1) { fprintf(stderr,_("search: Non-Fatal Error: Failed to read config.\n")); fprintf(stderr,_("search: Using default configuration information.\n")); } method = getenv("REQUEST_METHOD"); if(method == NULL) { /* Make the DB Connection. */ conn = db_connect(config); if(conn == NULL) { fprintf(stderr,"Failed to connect to the db.\n"); if(content != NULL) free(content); if(config != NULL) free(config); return -1; } debug_val = (char *)malloc(50); sprintf(debug_val,"%s","92987FBD"); search_by_keyid(conn,debug_val,config); /*search_by_uid(conn,"*****@*****.**",config); */ free(config); return 0; } if(method == NULL) { fprintf(stderr, _("search.c: Request Method is Null.\nExiting...\n")); free(config); return -1; } else if(strcmp(method,"GET") == 0) { content_length = strlen(getenv("QUERY_STRING")); if(content_length > 300) { do_error_page(_("Content Length expectation exceeded\n")); free(config); return -1; } content = (char *)malloc(content_length+1); if(content == NULL) { do_error_page(_("Server was unable to malloc memory. Server out of memory.")); free(config); return -1; } memset(content,0x00,content_length+1); strncpy(content,getenv("QUERY_STRING"),content_length); } else if(strcmp(method,"POST") == 0) { content_length = atoi(getenv("CONTENT_LENGTH")); if(content_length > 300) { do_error_page(_("Content Length expectation exceeded\n")); if(config != NULL) free(config); return -1; } content = (char *)malloc(content_length+1); if(content == NULL) { do_error_page(_("Server was unable to malloc memory. Server out of memory.")); if(content != NULL) free(content); if(config != NULL) free(config); return -1; } rslt = fread(content,1,content_length,stdin); if(rslt == 0) { do_error_page(_("Error reading content.")); if(content != NULL) free(content); if(config != NULL) free(config); return -1; } content[content_length] = '\0'; } else { do_error_page(_("Unknown Method.")); free(config); return -1; } hex_to_ascii(content); name = strtok(content,"&"); if(name == NULL) { fprintf(stderr,"name was null\n"); if(content != NULL) free(content); if(config != NULL) free(config); return -1; } val = strtok('\0',"\0"); if(!(val)) { do_error_page(_("Error: NULL Search value. Please, hit the back button on your browser and search again.")); if(content != NULL) free(content); if(config != NULL) free(config); return 0; } strtok(val,"="); value = strtok('\0',"\0"); if(!(value)) { do_error_page(_("Error: NULL Search value. Please, hit the back button on your browser and search again.")); if(content != NULL) free(content); if(config != NULL) free(config); return 0; } /* Test value for SQL injection */ if( (strchr(value, '\'') != NULL) || (strchr(value, ';') != NULL) ) { do_error_page(_("The characters ' and ; are currently not allowed in queries.")); if(content != NULL) free(content); if(config != NULL) free(config); return 0; } /* Make the DB Connection. */ conn = db_connect(config); if(conn == NULL) { fprintf(stderr,"Failed to connect to the db.\n"); if(content != NULL) free(content); if(config != NULL) free(config); return -1; } print_header(_("Search Results:")); if(strcmp("stype=uid",name) == 0) { search_by_uid(conn,value,config); } else if(strcmp("stype=fp",name) == 0) { rslt = search_by_fingerprint(conn,value,config); if(rslt != 0) { fprintf(stderr,"Function search_by_fingerprint() returned and error: %d\n", rslt); if(content != NULL) free(content); if(config != NULL) free(config); return -1; } } else if(strcmp("stype=keyid_4b",name) == 0) { if(memcmp(value,"00000000",8) == 0) { print_pgp5_x509_note(); } else { search_by_keyid(conn,value,config); } } else if(strcmp("stype=keyid_8b",name) == 0) { search_by_fkeyid(conn,value,config); } else if(strcmp("stype=keyring",name) == 0) { search_ret_keyring(conn,value,config); } else if(strcmp("stype=signers",name) == 0) { search_ret_with_signers(conn,value,config); } else { do_error_page(_("Invalid query. Search type not understood.")); db_disconnect(conn); if(content != NULL) free(content); if(config != NULL) free(config); return 0; } print_footer(); db_disconnect(conn); if(content != NULL) free(content); if(config != NULL) free(config); return 0; }
void create_task( const bool& GUI ){ if( GUI == true ){ // get the window size int maxX = getmaxx(stdscr); int maxY = getmaxy(stdscr); // generate an empty task Task newTask; bool exitLoop = false; int cursor = 0; int ncursor = 0; int cpos[3] = {0, 0, 0}; vector<int> npos(1,0); // print the new task ui while( !exitLoop ){ // clear the console clear(); // print the header print_header("New Task", maxX); // print the requred fields if( cursor == 0 ) attron( A_STANDOUT ); mvaddstr( 4, 1, (string("Name: ") + newTask.name).c_str() ); if( cursor == 0 ) attroff( A_STANDOUT ); if( cursor == 1 ) attron( A_STANDOUT ); mvaddstr( 5, 1, string("Groups: ").c_str()); if( cursor == 1 ) attroff( A_STANDOUT ); if( cursor == 2 ) attron( A_STANDOUT ); mvaddstr( 6, 1, string("Notes: ").c_str()); if( cursor == 2 ) attroff( A_STANDOUT ); for( size_t i=0; i<newTask.notes.size(); i++ ){ mvaddstr( 7+i, 2, newTask.notes[i].c_str()); } // print the footer print_footer( ADD_TASK, maxX, maxY ); // get user input int selection = getch(); string tempS; /// Quit if( selection == 27 ){ exitLoop = true; } else if( selection == KEY_UP ){ // make sure we are not in a note if( cursor == 0 || cursor == 1 ){ cursor--; if( cursor < 0 ){ cursor = 0; } } else if( cursor == 2 ){ ncursor--; if( ncursor < 0 ){ ncursor = 0; cursor--; } } else throw string("WHAT!"); } else if( selection == KEY_DOWN ){ // make sure we are not in a note if( cursor == 0 || cursor == 1 ){ cursor++; if( cursor == 2 ){ ncursor = 0; } } else if( cursor == 2 ){ ncursor++; if( ncursor >= newTask.notes.size() ){ ncursor = newTask.notes.size()-1; } } else throw string("WHAT!"); } /// User presses left/right arrow else if( selection == KEY_LEFT ){ if( cursor == 0 ){ if( cpos[0] > 0 ) cpos[0]--; } } else if( selection == KEY_RIGHT ){ if( cursor == 0 ){ if( cpos[0] < newTask.name.size()-1 ) cpos[0]++; } } /// User enters text else if( (selection >= 'a' && selection <= 'z') || (selection >= 'A' && selection <= 'Z') || selection == '.' || selection == ',' || selection == ' '){ tempS = (char)selection; if( cursor == 0 ){ newTask.name.insert(cpos[0], tempS); cpos[0]++; } } /// User presses backspace else if( selection == KEY_BACKSPACE ){ if( cursor == 0 ){ if( cpos[0] > 0 ){ newTask.name.erase( cpos[0], 1 ); cpos[0]--; } } } /// User presses delete else if( selection == KEY_DC ){ if( cursor == 0 ){ if( cpos[0] > 0 && cpos[0] < newTask.name.size()-1 ){ newTask.name.erase( cpos[0]+1, 1); } } } /// User Presses Enter else if( selection == KEY_ENTER ){ if(cursor == 0 || cursor == 1){ cursor++; } } } } }
int main(int argc, char *argv[]) { struct tanks_game game; struct tankdef mytankdefs[MAX_TANKS]; struct forftank myftanks[MAX_TANKS]; struct tank mytanks[MAX_TANKS]; struct forf_lexical_env lenv[LENV_SIZE]; int order[MAX_TANKS]; int ntanks = 0; int i; lenv[0].name = NULL; lenv[0].proc = NULL; if ((! forf_extend_lexical_env(lenv, forf_base_lexical_env, LENV_SIZE)) || (! forf_extend_lexical_env(lenv, tanks_lenv_addons, LENV_SIZE))) { fprintf(stderr, "Unable to initialize lexical environment.\n"); return 1; } /* We only need slightly random numbers */ { char *s = getenv("SEED"); int seed = atoi(s?s:""); if (! seed) { seed = getpid(); } srand(seed); fprintf(stdout, "// SEED=%d\n", seed); } if(argc > 1){ /* Every argument is a tank directory */ ntanks = argc-1; // argc[0] is program name, not a tank. if(ntanks > MAX_TANKS) { fprintf(stderr, "Too many tanks! Tried to load: %d, Max: %d", ntanks, MAX_TANKS); return 1; } for (i = 0; i < ntanks; i++) { //&L changed loop. mytankdefs[i] = readTankFromDir(argv[i+1]); } } else { // Expecting JSON on stdin. char* jsonString = malloc(sizeof(char)*MAX_JSON_SIZE); char c; long size = 0; while( (c=fgetc(stdin)) != EOF ) { jsonString[size] = c; size++; if(size>=(MAX_JSON_SIZE-1)) { fprintf(stderr,"Error: JSON text too large.\n"); return 1; } } jsonString[size] = '\0'; ntanks = jsonArraySize(jsonString); // argc[0] is program name, not a tank. if(ntanks > MAX_TANKS) { fprintf(stderr, "Too many tanks! Tried to load: %d, Max: %d", ntanks, MAX_TANKS); return 1; } readTanksFromJSON(mytankdefs, ntanks, jsonString); } if (0 == ntanks) { fprintf(stderr, "No usable tanks!\n"); return 1; } for(i=0; i < ntanks; i++) { ft_read_tank(&myftanks[i], &mytanks[i], lenv, &mytankdefs[i]); } /* Calculate the size of the game board */ { int x, y; for (x = 1; x * x < ntanks; x += 1); y = ntanks / x; if (ntanks % x) { y += 1; } game.size[0] = x * SPACING; game.size[1] = y * SPACING; } /* Shuffle the order we place things on the game board */ for (i = 0; i < ntanks; i += 1) { order[i] = i; } for (i = 0; i < ntanks; i += 1) { int j = rand() % ntanks; int n = order[j]; order[j] = order[i]; order[i] = n; } /* Position tanks */ { int x = SPACING/2; int y = SPACING/2; for (i = 0; i < ntanks; i += 1) { mytanks[order[i]].position[0] = (float)x; mytanks[order[i]].position[1] = (float)y; mytanks[order[i]].angle = deg2rad(rand() % 360); mytanks[order[i]].turret.current = deg2rad(rand() % 360); mytanks[order[i]].turret.desired = mytanks[order[i]].turret.current; x += SPACING; if (x > game.size[0]) { x %= (int)(game.size[0]); y += SPACING; } } } print_header(stdout, &game, myftanks, mytanks, ntanks); print_rounds(stdout, &game, mytanks, ntanks); print_footer(stdout); /* Output standings to fd3. * * fd 3 is normally closed, so this won't normally do anything. * To output to fd3 from the shell, you'll need to do something like this: * * ./run-tanks 3>standing **/ { FILE *standings = fdopen(3, "w"); if (standings) { print_standings(standings, myftanks, mytanks, ntanks); } } delete_tanks(myftanks, ntanks); return 0; }