Solved

ercis

Posted on 2000-02-24
6
190 Views
Last Modified: 2010-04-02
Please answer this for your points.
0
Comment
Question by:rkcth
  • 3
  • 3
6 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 2556603
I believe this is for

http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=10299447 

correct?  (Always good to provide "justification".)
0
 
LVL 1

Accepted Solution

by:
ercis earned 50 total points
ID: 2559893
/***

this will do more: create 1x1 dot with specified color...
compile: gcc -Wall -s -o dot.cgi dot.c
and write in html:
 <img src="http://host.com/cgi-bin/dot.cgi?FF0000" width="50" height="5">

***/


#include <stdio.h>
#include <stdlib.h>

char x2c(char *what) {
   register char digit;
   digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0'));
   digit *= 16;
   digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0'));
   return(digit);
}

const unsigned char IMAGE_GIF1[] = {
   0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00,
   0x01, 0x00, 0x80, 0xFF, 0x00, 0xFF, 0xFF, 0xFF };

const unsigned char IMAGE_GIF2[] = {
                     0x2C, 0x00, 0x00, 0x00, 0x00,
   0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x4C,
   0x01, 0x00, 0x3B };

int main(int argc, char *argv[])
{
   char *input, *p, *e;
   long l1 = sizeof(IMAGE_GIF1);
   long l2 = sizeof(IMAGE_GIF2);


   if( (p=getenv("REQUEST_METHOD")) && !strcmp(p, "GET") &&
       (p=getenv("QUERY_STRING")) && strlen(p) > 5 )
      input = p;
   else
      if(argc > 1 && strlen(argv[1]) > 5)  input = argv[1];
         else
            input = "ffffff";  // default = white

   printf("Content-type: image/gif\r\n");
   printf("Content-Length: %lu\r\n\r\n", l1 + 3 + l2);

   p = (char *)IMAGE_GIF1;
   e = p + l1;

   do
   {
     putchar(*p);
   }
   while (++p < e);

   putchar(x2c(input));
   putchar(x2c(input + 2));
   putchar(x2c(input + 4));

   p = (char *)IMAGE_GIF2;
   e = p + l2;

   do
   {
     putchar(*p);
   }
   while (++p < e);

   exit(0);
}

// nietod can make some optimizations :)
// maybe fwrite(IMAGE_GIF, sizeof(IMAGE_GIF), 1, stdout);
0
 
LVL 22

Expert Comment

by:nietod
ID: 2560921
Instead of

p = (char *)IMAGE_GIF1;
e = p + l1;

do
{
   putchar(*p);
}
while (++p < e);

I would just do

cout.write(IMAGE_GIF1,sizeof(IMAGE_GIF1));

it is simpler and likely to be faster.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 1

Expert Comment

by:ercis
ID: 2562971
yes, but I'm talking about C, not C++
0
 
LVL 22

Expert Comment

by:nietod
ID: 2562994
But this is the C++ topic area.  We kill for less.  :-)
0
 
LVL 1

Expert Comment

by:ercis
ID: 2563462
nietod: sorry, I omited that :)
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question