int main (int argc, char *argv[]) { long px, py; size_t intc; long *intv; if (argc != 4) return usage (); // the first to arguments are interpreted respectively as X and Y coordinates of the point of interest px = require_number (argv[1]); py = require_number (argv[2]); // the third argument is interpreted as the filename // from which we are reading intv = read_numbers (argv[3], &intc); if (intv == NULL) { (void)puts ("main: error parsing points file"); return EXIT_FAILURE; } if (intc % 2 != 0) { printf ("main: got %lu numbers, but expected an even number (pairs)\n", (unsigned long)intc); xfree (intv); return EXIT_FAILURE; } // call the algorithm that calculates wheter the point is inside the polyon { rc_ctx *ctx = rc_new (intc, intv); printf ("%s\n", rc_contains (ctx, px, py) ? "inside" : "outside"); rc_delete (ctx); } xfree (intv); return EXIT_SUCCESS; }
static int rcdel(const char *archive, char **members) { RcArchive rca = rc_open_archive(archive, RC_RDWR|RC_CREATE); char *rcclass = "data"; size_t clen = strlen("--class="); if ( !rca ) return badarchive(archive); if ( members ) { for( ; *members; members++ ) { char *m = *members; if ( strncmp(m, "--class=", clen) == 0 ) { rcclass = m+clen; continue; } if ( !rc_delete(rca, m, rcclass) ) error("Could not delete \"%s\": %s", m, rc_strerror(rc_errno)); else verbose("d %s\n", m); } } if ( rca->modified ) { if ( !rc_save_archive(rca, NULL) ) { error("Failed to create \"%s\": %s", archive, rc_strerror(rc_errno)); return 1; } } rc_close_archive(rca); return 0; }