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

📄 cgimagick.c

📁 下载来的一个看图软件的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
%%  A description of each parameter follows:%%    o text:  Specifies the string to segment into a list.%%    o argc:  This integer pointer returns the number of arguments in the%             list.%%    o argv:  This array of pointers returns the string list unless an error%             occurs, otherwise NULL.%*/#define IsCGIDelimiter(c)  (((c) == '&') || ((c) == '=') || ((c) == '\0'))unsigned int CGIToArgv(const char *text,int *argc,char ***argv){  char    **vector;  const char    *p,    *q;  register int    i;  int    count;  assert(argc != (int *) NULL);  assert(argv != (char ***) NULL);  if (text == (char *) NULL)    return(False);  if (argc == (int *) NULL)    return(False);  if (argv == (char ***) NULL)    return(False);  /*    Determine the number of arguments by scanning for delimiters  */  q=text;  count=0;  while (1)  {    int      len;    p=q;    while (!IsCGIDelimiter(*q))      q++;    len=q-p;    if (len > 0)      count++;    if (*q == '\0')      break;    q++;  }  vector=(char **) AcquireMemory((count+2)*sizeof(char *));  if (vector == (char **) NULL)    {      MagickError(ResourceLimitError,"Unable to convert string to argv",        "Memory allocation failed");      return(False);    }  /*    Convert string to an ASCII list.  */  vector[0]=AllocateString("cgimagick");  vector[count+1]=(char *) NULL;  q=text;  i=1;  while (i <= count)  {    int      len;    p=q;    while (!IsCGIDelimiter(*q))      q++;    /*       Skip an zero length tokens. This typically happens for the case       of xxx=& on a CGI GET or POST were the name value pair has no       value    */    len=q-p;    if (len > 0)      {        vector[i]=(char *) AcquireMemory(q-p+1);        if (vector[i] == (char *) NULL)          {            MagickError(ResourceLimitError,"Unable to convert string to argv",              "Memory allocation failed");            return(False);          }        (void) strncpy(vector[i],p,q-p);        vector[i][q-p]='\0';        /*          Convert any special HTML codes in place back to ASCII        */        HttpUnescape(vector[i], (char *) NULL);        i++;      }    q++;  }  *argc=count+1;  *argv=vector;  return(True);}/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                                                                             %%                                                                             %%                                                                             %%  G e t F i l e M i m e T y p e                                              %%                                                                             %%                                                                             %%                                                                             %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  Method GetFileMimeType given the file name, obtain MIME type for%  "Content-type:" header field. We try to find MIME type string under%  HCR\.xyz key, "Content Type" value. If that fails, we return default%  "application/ocetet-stream".%%  The format of the GetFileMimeType method is:%%      void GetFileMimeType(LPCSTR pszPath, LPSTR pszType, DWORD cbMax)%%  A description of each parameter follows:%%    o pszPath:  file path%%    o pszType:  points to the buffer that will receive MIME type string%%    o cbMax:    specifies the maximum number of characters to copy to the%                buffer, including the NUL character. If the text exceeds%                this limit, it will be truncated.%*/typedef struct _mime_spec{  char    *extn,    *type;} mime_spec;static mime_spec specs[] = {  { (char *) ".", (char *) "text/plain" },  { (char *) ".htm", (char *) "text/html" },  { (char *) ".html", (char *) "text/html" },  { (char *) ".txt", (char *) "text/plain" },  { (char *) ".gif", (char *) "image/gif" },  { (char *) ".jpe", (char *) "image/jpeg" },  { (char *) ".jpeg", (char *) "image/jpeg" },  { (char *) ".jpg", (char *) "image/jpeg" },  { (char *) ".pbm", (char *) "image/x-portable-bitmap" },  { (char *) ".pgm", (char *) "image/x-portable-graymap" },  { (char *) ".png", (char *) "image/png" },  { (char *) ".pnm", (char *) "image/x-portable-anymap" },  { (char *) ".ppm", (char *) "image/x-portable-pixmap" },  { (char *) ".ras", (char *) "image/x-cmu-raster" },  { (char *) ".rgb", (char *) "image/x-rgb" },  { (char *) ".tif", (char *) "image/tiff" },  { (char *) ".tiff", (char *) "image/tiff" },  { (char *) ".xbm", (char *) "image/x-xbitmap" },  { (char *) ".xpm", (char *) "image/x-xpixmap" },  { (char *) ".xwd", (char *) "image/x-xwindowdump" },  { (char *) ".avi", (char *) "video/msvideo" },  { (char *) ".mov", (char *) "video/quicktime" },  { (char *) ".mpe", (char *) "video/mpeg" },  { (char *) ".mpeg", (char *) "video/mpeg" },  { (char *) ".mpg", (char *) "video/mpeg" },  { (char *) ".mp3", (char *) "audio/mpeg" },  { (char *) ".wav", (char *) "audio/wav" },  { (char *) ".bin", (char *) "application/octet-stream" },  { (char *) ".eps", (char *) "application/postscript" },  { (char *) ".exe", (char *) "application/octet-stream" },  { (char *) ".gtar", (char *) "application/x-gtar" },  { (char *) ".gz", (char *) "application/x-gzip" },  { (char *) ".hdf", (char *) "application/x-hdf" },  { (char *) ".jar", (char *) "application/java-archive" },  { (char *) ".lzh", (char *) "application/x-lzh" },  { (char *) ".pdf", (char *) "application/pdf" },  { (char *) ".ps", (char *) "application/postscript" },  { (char *) ".tar", (char *) "application/tar" },  { (char *) ".tgz", (char *) "application/x-gzip" },  { (char *) ".zip", (char *) "application/zip" }};void GetFileMimeType(const char *pszPath, char *pszType, unsigned long cbMax){  char    *pszExt;  /*    set MIME type to empty string  */  *pszType = '\0';  /*    try to locate file extension  */  pszExt = (char *) strrchr( pszPath, '.');      if (pszExt != NULL)    {#ifdef USE_REGISTRY         HKEY        hKey;      unsigned long        value_type;      long        result;      /*         for file extension .xyz, MIME Type can be found        HKEY_CLASSES_ROOT\.xyz key in the registry      */      result = RegOpenKeyEx(HKEY_CLASSES_ROOT,pszExt,0L,KEY_READ,&hKey);                           if (result == ERROR_SUCCESS)        {          /*            we sucessfully opened the key.            try getting the "Content Type" value          */                      result = RegQueryValueEx(hKey,"Content Type",NULL,&value_type, 	                   (BYTE *)pszType,&cbMax);          /*            if we failed to get the value or it is not string,            clear content-type field          */                      if (result != ERROR_SUCCESS || value_type != REG_SZ)              *pszType = '\0';          RegCloseKey( hKey );        }#else      int        i,        tagcount = sizeof(specs) / sizeof(mime_spec);      /* try to match this record to one of the ones in our named table */      for (i=0; i< tagcount; i++)      {        if (LocaleCompare(specs[i].extn,pszExt) == 0)          strncpy(pszType, specs[i].type, cbMax);      }#endif    }      /*    if at this point we don't have MIME type, use default  */      if (*pszType == '\0')    strncpy(pszType, "application/octet_stream", cbMax);}/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                                                                             %%                                                                             %%                                                                             %%  M a i n                                                                    %%                                                                             %%                                                                             %%                                                                             %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/#define IMAGELIST_SIZE  8int main(int argc,char **argv){  char    **argv_hw,    *errmsg,    prefix[MaxTextExtent];  int    argc_hw,    i,    list_position;  unsigned int    impersonating,    status;  Image    *imag_list[IMAGELIST_SIZE];  ImageInfo    *info_list[IMAGELIST_SIZE];  /*    Initialize command line arguments.  */  impersonating=False;  errmsg=(char *) NULL;  ReadCommandlLine(argc,&argv);  InitializeMagick(*argv);  for (i=0; i < IMAGELIST_SIZE; i++)  {    imag_list[i]=(Image *) NULL;    info_list[i]=(ImageInfo *) NULL;  }  list_position=0;#if defined(_VISUALC_)  _setmode(_fileno(stdout),_O_BINARY);#endif	if (getenv("GATEWAY_INTERFACE") || (argc>1))    {      if (!getenv("GATEWAY_INTERFACE"))        status=CGIToArgv(argv[1],&argc,&argv);      else        {          char            *query;          query=CGIGetInput(CGI_ANY);          status=CGIToArgv(query,&argc,&argv);          LiberateMemory((void **) &query);        }      if (status == True)        {          char            szMimeType[MaxTextExtent],            szPathTranslated[MaxTextExtent];          szPathTranslated[0] = '\0';          

⌨️ 快捷键说明

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