⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cgimagick.c

📁 下载来的一个看图软件的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                                                                             %%                             C G I M A G I C K                               %%                                                                             %%                                                                             %%        A shim layer to give command line utilities a CGI interface.         %%                                                                             %%                                                                             %%                                                                             %%                              Software Design                                %%                           William T. Radcliffe                              %%                                June 2001                                    %%                                                                             %%                                                                             %%  Copyright (C) 2001 ImageMagick Studio, a non-profit organization dedicated %%  to making software imaging solutions freely available.                     %%                                                                             %%  Permission is hereby granted, free of charge, to any person obtaining a    %%  copy of this software and associated documentation files ("ImageMagick"),  %%  to deal in ImageMagick without restriction, including without limitation   %%  the rights to use, copy, modify, merge, publish, distribute, sublicense,   %%  and/or sell copies of ImageMagick, and to permit persons to whom the       %%  ImageMagick is furnished to do so, subject to the following conditions:    %%                                                                             %%  The above copyright notice and this permission notice shall be included in %%  all copies or substantial portions of ImageMagick.                         %%                                                                             %%  The software is provided "as is", without warranty of any kind, express or %%  implied, including but not limited to the warranties of merchantability,   %%  fitness for a particular purpose and noninfringement.  In no event shall   %%  ImageMagick Studio be liable for any claim, damages or other liability,    %%  whether in an action of contract, tort or otherwise, arising from, out of  %%  or in connection with ImageMagick or the use or other dealings in          %%  ImageMagick.                                                               %%                                                                             %%  Except as contained in this notice, the name of the ImageMagick Studio     %%  shall not be used in advertising or otherwise to promote the sale, use or  %%  other dealings in ImageMagick without prior written authorization from the %%  ImageMagick Studio.                                                        %%                                                                             %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  This is a simple shim that provides a CGI layer for calling into any of the%  normal command line utilities.*//*  Include declarations.*/#include "magick/magick.h"#include "magick/define.h"/*  Include the convert mainline as a subroutine*/#define Usage convert_Usage#define main convert_main#include "utilities\convert.c"#undef Usage#undef main/*  Include the combine mainline as a subroutine*/#define Usage combine_Usage#define main combine_main#include "utilities\composite.c"#undef Usage#undef main/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                                                                             %%                                                                             %%                                                                             %%  C G I F i f o                                                              %%                                                                             %%                                                                             %%                                                                             %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  Method CGIFifo is the default output stream handler for CGI usage. It is%  called by the stream subsystem whenever a buffer of data needs to be sent%  to the output.It receives a pointer to the image as well as the buffer%  of data and its length.%%  The format of the HttpUnescape method is:%%      int CGIFifo(const Image *image,const void *data,const size_t length)%%  A description of each parameter follows:%%    o image:  A pointer to the image being sent to the output stream.%%    o data: A pointer to the buffer of data to be sent.%%    o length: The length of the buffer of data to be sent.%*/int CGIFifo(const Image *image,const void *data,const size_t length){  fwrite(data,1,length,stdout);  return(length);}/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                                                                             %%                                                                             %%                                                                             %%  D e c o d e H e x                                                          %%                                                                             %%                                                                             %%                                                                             %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  Method DecodeHex decodes a hexadecimal string. It stops after outmax%  characters or when an invalid hex character is reached. It also sets%  the input pointer to the first unprocessed character.  Returns the%  the result as a binary number.%%  The format of the HttpUnescape method is:%%      int DecodeHex(const char **input,size_t outmax)%%  A description of each parameter follows:%%    o input:  Specifies the string to be converted.%%    o outmax: Specifies the maximum number of characters to process.%*/int DecodeHex(const char **input,size_t outmax){  static char    hex_to_bin [128] = {      -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,    /*            */      -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,    /*            */      -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,    /*            */       0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1,    /*   0..9     */      -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,    /*   A..F     */      -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,    /*            */      -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,    /*   a..f     */      -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 };  /*            */  int    nextch;  size_t    index,    result;  assert(input != (const char **) NULL);  assert((*input) != (const char *) NULL);  index  = 0;  result = 0;  while (outmax == 0 || index < outmax)  {    nextch = (*input) [index] & 127;    if (nextch && hex_to_bin [nextch] != -1)    {      result = result * 16 + hex_to_bin [nextch];      index++;    }    else      break;  }  (*input) += index;  return (result);}/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                                                                             %%                                                                             %%                                                                             %%  H t t p U n e s c a p e                                                    %%                                                                             %%                                                                             %%                                                                             %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  Method HttpUnescape removes HTTP escaping from a string. If the result%  string is NULL, it modifies the source string in place, else fills-in%  the result string. This method returns the resulting string. End-of-line%  sequences (%0A%0D) are stored as a single new-line character, i.e.%  carriage-returns (%0D) are not stored.%%  The format of the HttpUnescape method is:%%      char *HttpUnescape(char *string,char *result)%%  A description of each parameter follows:%%    o string:  Specifies the string to be converted.%%    o result:  Specifies the destination for the converted result. A NULL%               indicates that the conversion happens "in-place".%*/char *HttpUnescape(char *string,char *result){  char    *target; /* Where we store the result */  assert(string != (char *) NULL);  if (!result) /* If result string is null, */    result = string; /* modify in place */  target = result;  while (*string)  {    if (*string == '%'  /* Unescape %xx sequence */          && isxdigit((int) string [1]) && isxdigit((int) string [2]))      {        string++;        *target = DecodeHex ((const char **) &string, 2);        if (*target != '\r')          target++; /* We do not store CR's */      }    else      {        if (*string == '+') /* Spaces are escaped as '+' */          *target++ = ' ';        else          *target++ = *string; /* Otherwise just copy */        string++;      }  }  *target = '\0'; /* Terminate target string */  return (result);}/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                                                                             %%                                                                             %%                                                                             %%  C G I G e t I n p u t                                                      %%                                                                             %%                                                                             %%                                                                             %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  Method CGIGetInput returns the result of a CGI GET or POST request to the%  caller as a simple string buffer.%%  The format of the CGIGetInput method is:%%      char *CGIGetInput(CGIAccessType method)%%  A description of each parameter follows:%%    o method:  Specifies the type of access to look for. This can be GET,%               POST, or both (the most typical).%*/typedef enum{  CGI_GET,  CGI_POST,  CGI_ANY} CGIAccessType;char *CGIGetInput(CGIAccessType iMethod){  char    *strHead,    *strRetBuf;  int    iStdinLen = 0,    iMethodWas = 0;  if (iMethod == CGI_POST || iMethod == CGI_ANY)    {      if (getenv ("CONTENT_LENGTH"))        {          iStdinLen = atoi (getenv ("CONTENT_LENGTH"));          iMethodWas = CGI_POST;        }    }  if (iMethod == CGI_GET || (iMethod == CGI_ANY && !iStdinLen))    {      if (getenv ("QUERY_STRING"))        {          iStdinLen = strlen (getenv ("QUERY_STRING"));          iMethodWas = CGI_GET;        }    }  if (!iStdinLen)      return (NULL);  strHead = strRetBuf = (char *) AcquireMemory(sizeof (char) * iStdinLen + 1);  if (strHead == (char *) NULL)      return (NULL);  memset (strRetBuf, 0, iStdinLen + 1);  if (iMethodWas == CGI_POST)    {#ifdef WIN32			setmode(fileno(stdin), O_BINARY);#endif      fread (strRetBuf, sizeof (char), iStdinLen, stdin);    }  else    strncpy (strRetBuf, getenv ("QUERY_STRING"), (iStdinLen + 1));  return (*strHead? strHead: NULL);}/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                                                                             %%                                                                             %%                                                                             %%  C G I T o A r g v                                                          %%                                                                             %%                                                                             %%                                                                             %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  Method CGIToArgv converts a text string passed as part of a CGI request%  into command line arguments.%%  The format of the CGIToArgv method is:%%      char **CGIToArgv(const char *text,int *argc,char ***argv)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -