/* ==================================================================== * * (c) Rafael Hernandez rhm@stanford.edu 2001 * * ==================================================================== */ /* example cookie: @PHOTOCART=|4:stieglitz_snapshot_paris.jpg:234|1||3:stieglitz_selfportrait.jpg:1000|1| */ #include #include #include #include "cgi.h" /* * NAME * main * DESCRIPTION * Show our current shopping cart * All the info is encoded in the cookie * The cookie format is * |catalogn|image|price|quantity| * quantity is always 1 * as can be seen in this example cookie: * @PHOTOCART=|4:stieglitz_snapshot_paris.jpg:234|1||3:stieglitz_selfportrait.jpg:1000|1| * */ int main(int argc, char *argv[]) { int i = 0, j, k, done = 0; float price, total=0; char whole_cookie[4092], *my_cookie[300], *cookie_name, *tmp; char *quant, *description, *catalogn, *pr, *next; if (argc == 2) { printf(""); } else PrintHTMLHeader(); /* Process the cookie */ whole_cookie[0] = 0; if (!getenv("HTTP_COOKIE") || !strcmp(getenv("HTTP_COOKIE"),"")) { printf("
YOUR CART IS EMPTY
"); } else { strcpy(whole_cookie, getenv("HTTP_COOKIE")); tmp = whole_cookie; while (*++tmp != '='); *tmp = 0; cookie_name = whole_cookie; printf("

Current Shopping Cart

"); if (!strcmp("@PHOTOCART", cookie_name)) { printf(""); k = 0; tmp++; while ((next = strstr(tmp, "|")) != NULL) { next++; tmp = next; while (*++tmp != ':'); *tmp++ = 0; catalogn = next; next = tmp; while (*++tmp != ':'); *tmp++ = 0; description = next; next = tmp; while (*++tmp != '|'); *tmp++ = 0; pr = next; price = atof(pr); next = tmp; while (*++tmp != '|'); *tmp++ = 0; quant = next; printf("\n", catalogn, homepage, description, description, pr); printf("\n", total); printf("
CATALOGIMAGEPRICE
%s%s%s
", homepagecgi, k); ++k; total = total + price; } printf("
Total$%.2f
"); } }/* else */ PrintHTMLEnd(); return 0; }