All pastes #464047 Raw Edit

Anonymous

public text v1 · immutable
#464047 ·published 2007-04-29 08:52 UTC
rendered paste body
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left">/*   * VFW Compressor Settings Tool   *   * Copyright (c) 2006 Gianluigi Tiesi <sherpya@netfarm.it>   *   * This program is free software;  you can redistribute it and/or   * modify it under the terms of the GNU Library General Public   * License as  published by the Free Software Foundation; either   * version 2 of the License,  or (at your option) any later version.</span>/*vfw压缩机设置工具*版权所有(C)2006詹路易吉tiesi<sherpya@netfarm.it>*这个节目是免费软件;您可以重新分配和/或*修改它的条件下GNU的库一般公众执照*内容出版的自由软体基金会;either*version2ofthelicense,or(atyouroption)anylaterversion. </span><span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left">*   * This library is distributed in the hope that it will be useful,   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</span>*本图书发行,希望它将是有益的,*但没有任何保修;甚至隐含保修*适销或适合特定用途. </span><span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left">See the GNU   * Library General Public License for more details.</span>看到gnu*图书馆公众执照更多细节. </span><span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left">*   * You should have received a copy of the GNU Library General Public   * License along with this software; if not, write to the   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,  MA 02110-1301 USA   */    /* On mingw compile with: gcc getopt.c vfw2menc.c -o vfw2menc.exe -lwinmm */  /* Using wine:  winegcc getopt.c vfw2menc.c -o vfw2menc -lwinmm */    #ifdef _MSC_VER  #define _CRT_SECURE_NO_DEPRECATE  #pragma warning(disable:  4996)  #endif    #include <stdio.h>  #include <stdlib.h>  #include <sys/stat.h>  #include <getopt.h>  #include <windows.h>  #include <vfw.h>    #define BAIL(msg) { printf("%s: %s\n",  argv[0], msg); ret = -1; goto cleanup; }    enum  {      MODE_NONE = 0,      MODE_CHECK,      MODE_SAVE,      MODE_VIEW  };  int save_settings(HDRVR hDriver, const char *filename)  {      FILE *fd = NULL;      DWORD cb = (DWORD) SendDriverMessage(hDriver, ICM_GETSTATE, 0, 0);     char *pv = NULL;        if (!cb)      {          printf("ICM_GETSTATE returned 0 size\n");          return -1;      }        pv = (char *) malloc(cb);       if (SendDriverMessage(hDriver, ICM_GETSTATE, (LPARAM) pv, (LPARAM) &cb) != ICERR_OK)      {          printf("ICM_GETSTATE failed\n");          free(pv);          return -1;      }        fd = fopen(filename, "wb") ;      if (!fd)      {          printf("Cannot open file %s for writing\n", filename);          free(pv);          return -1;      }        if (fwrite(pv, cb, 1, fd) ! = 1)      {          printf("fwrite() failed on %s\n", filename);          free(pv);          fclose(fd);          return -1;      }      fclose(fd);      free(pv);      return 0;  }    int load_settings(HDRVR hDriver, const char *filename)  {      struct stat info;      FILE *fd = NULL;      char *pv;        if (stat(filename, &info) < 0)      {          printf("stat() on %s failed\n", filename);          return -1;      }        pv = (char *) malloc(info.st_size);      fd = fopen(filename, "rb");        if (!fd)      {          printf("Cannot open file %s for reading\n", filename);          free(pv);          return -1;      }   if (fread(pv, info.st_size, 1, fd) != 1)      {          printf("fread() failed on %s\n", filename);          free(pv);          fclose(fd);          return -1;      }      fc lose(fd);      if (!SendDriverMessage(hDriver, ICM_SETSTATE, (LPARAM) pv, (LPARAM) info.st_size))      {          printf("ICM_SETSTATE failed\n");          free(pv);          return -1;      }      free(pv);      return 0;  }    static s truct option long_options[] =  {      { "help",   no_argument,        NULL,   'h' },      { "driver", required_argument,  NULL,   'd' },      { "fourcc ", required_argument,  NULL,   'f' },      { "save",   required_argument,  NULL,   's' },      { "check",  required_argument,  NULL,   'c' },      { "view", no_argument,        NULL,   'v' },      { 0, 0, 0, 0 }  };    void help(cons t char *progname)  {      printf("VFW to mencoder - Copyright 2006 - Gianluigi Tiesi <sherpya@netfarm.it>\n");      printf("This program is Free Software\n\n");      printf("Usage: %s\n", progname);      printf("      -h|--help            - displays this help\n");      printf("      -d|--driver filename - dll or drv to load\n");      printf("       -f|--fourcc fourcc   - fourcc of selected driver (look at codecs.conf)\n");      printf("      -s|--save filename   - save settings to file\n");      printf("       -c|--check filename  - load and show setting in filename\n");      printf("       -v|--view            - displays the config dialog and do nothing\n");      printf("\nExamples:\n");      printf(" %s -f VP62 -d vp6vfw.dll -s firstpass.mcf\n", progname);      pri ntf(" %s -f VP62 -d vp6vfw.dll -c firstpass.mcf\n", progname);      printf(" %s -f VP62 -d vp6vfw.dll -v\n", progname);      printf("\nIf t he driver dialog doesn't work, you can try without specifing a fourcc,\n");      printf("but th e compdata file will not work with mencoder.\n");      printf("Driver option is required and you must specify at least -s, -c -o -v\n");      printf("Usage w ith mencoder -ovc vfw -xvfwopts codec=vp6vfw.dll:compdata=settings.mcf\n");  }      int main(int argc, char *argv[])  {      char *driver = NULL;      char *fourcc =  NULL;      char *filename = NULL;      unsigned char mode = 0;        wchar_t drvfile[MAX_PATH];      HDRVR hDriver = NULL;      int ret = 0;    int c = -1, long_options_index = -1;        if (argc < 2)      {          help(argv[0]);          ret = -1;      goto cleanup;      }        while ((c = getopt_long(argc, argv, "hd:f:s:c:v", long_options, &long_options_index)) != -1) {          switch (c)          {              case 'h':                  help(argv[0]);                  ret = 0;                  goto cleanup;              case 'd':                  driver = strdup(o ptarg);                  break;              case 'f':                  fourcc = strdup(optarg);                  if (strlen(optarg) != 4) BAIL("Fourcc must be exactly 4 chars");                  break;            case 's':                  if (mode != MODE_NONE) BAIL("Incompatible arguments");                  filename = strdup(optarg);                  mode = MODE_SAVE;                  break;              case 'c':                  if (mode != MODE_NON E) BAIL("Incompatible arguments");                  filename = strdup(optarg);                  mode = MODE_CHECK;                  break;              case 'v':                  if (mode != MODE_NON E) BAIL("Incompatible arguments");                  mode = MODE_VIEW;                  break;              default:                  printf("Wrong arguments!\n");          }      }          if (!(argc == optind) && (mode != MODE_NONE) &&          driver && (filename || (mode == MODE_VIEW)))      {          help(argv[0]);          goto cleanup;      }        i f (!MultiByteToWideChar(CP_ACP, 0, driver, -1, drvfile, MAX_PATH))          BAIL("MultiByteToWideChar() failed\n");        if (!(hDriver = OpenDriver(drvfile, 0, (fourcc) ? ((LPARAM) fourcc) : 0)))    BAIL("OpenDriver() failed\n");        if (SendDriverMessage(hDriver, ICM_CONFIGURE, -1, 0) != ICERR_OK)          BAIL("The driver doe sn't provide a configure dialog");        switch(mode)      {          case MODE_CHECK:              if (load_settings(hDriver, filename))                  BAIL("Cannot load settings from file");              if (SendDriverMessage(hDriver, ICM_CONFIGURE, 0, 0) != ICERR_OK)                  BAIL("ICM_CONFIGURE failed");              break;          case MODE_SAVE:              if (SendDriverMessage(hDriver, IC M_CONFIGURE, 0, 0) != ICERR_OK)                  BAIL("ICM_CONFIGURE failed");              if (save_settings(hDriver, filename))                  BAIL("Cannot save settings to file");              break;          case MODE_VIEW:              if (Send DriverMessage(hDriver, ICM_CONFIGURE, 0, 0) != ICERR_OK)                  BAIL("ICM_CONFIGURE failed");              break;          default:              BAIL("This should not happen :)");      }    cleanup:      if (driver) free(drive r);      if (fourcc) free(fourcc);      if (filename) free(filename);      if (hDriver) CloseDriver(hDriver, 0, 0);      return ret;  }</span>**你应该已经收到一份GNU的库一般公众执照*随着这一软件;如果没有,写信给*基金会,51富兰克林街五楼波士顿马02110-1301美国*//*mingw编译:gccgetopt.cvfw2menc.c-澳vfw2menc.exe-lwinmm*//*用酒:winegccgetopt.cvfw2menc.c-澳vfw2menc-lwinmm*/#11:35_msc_ver#define_crt_secure_no_deprecate#pragmawarning(disable:4996)#endif#包括<stdio.h>#包括<stdlib.h>#包括<sys/stat.h>#包括<getopt.h>#包括<windows.h>#包括<vfw.h>#define保释(msg)(printf("%s:%s\n",argv[0],msg);ret=-1;gotocleanup;enum(mode_none=0,mode_check,mode_save,mode_view).intsave_settings(hdrvrhdriver,constchar*filename)(file*fd=null;dwordcb=(dword)senddrivermessage(hdriver,icm_getstate,0,0);char*pv=null;如果(!cb)(printf("icm_getstate返回0大小\n");返回-1;pv=(char*)malloc(cb);如果(senddrivermessage(hdriver,icm_getstate,(lparam)光电(lparam)及CB)!=icerr_ok)(printf("icm_getstatefailed\n");free(pv);返回-1;fd=fopen(filename,"wb");如果(!199)(printf("不能打开文件%s写作\n",filename);free(pv);返回-1;if(fwrite(pv,cb,1,199)!=1)(printf("fwrite()失败%s\n",filename);free(pv);fclose(fd);返回-1;fclose(fd);free(pv);返回0;intload_settings(hdrvrhdriver,constchar*filename)(structstatinfo;档案*fd=null;char*逐;if(stat(filename,&info)"0)(printf("stat()%sfailed\n",filename);返回-1;pv=(char*)malloc(info.st_size);fd=fopen(filename,"rb");如果(!199)(printf("不能打开文件%s看书\n",filename);free(pv);返回-1;if(fread(pv,info.st_size,1,199)!=1)(printf("fread()失败%s\n",filename);free(pv);fclose(fd);返回-1;财失去(199);如果(!senddrivermessage(hdriver,icm_setstate,(lparam)光电(lparam)info.st_size))(printf("icm_setstatefailed\n");free(pv);返回-1;free(pv);返回0;静s解构optionlong_options[]={("帮助",no_argument,null,'h'),("驱动",required_argument,null,'d'),("fourcc"required_argument,null,'f'),("保存",required_argument,null,'s'),("检查",required_argument,null,'c'),("观点"no_argument,null,'v'),{0,0,0,0);voidhelp(constchar*progname)(printf("vfw以mencoder-版权-2006詹路易吉tiesi<sherpya@netfarm.it>\n");printf("程式是自由软体\n\n");printf("usage:%s\n",progname);printf("-h|--help-显示帮助\n");printf("-d|--司机filename-dll或drv负荷\n");printf("-f|--fourccfourcc-fourcc选定司机(看看codecs.conf)\n");printf("-s|--拯救filename-储存设定档案\n");printf("-三|--checkfilename负荷显示设置filename\n");printf("-v|--查看显示configdialog,无所作为\n");printf("\nexamples:\n");printf("%s-fvp62-dvp6vfw.dll-sfirstpass.mcf\n",progname);printf("%s-fvp62-dvp6vfw.dll-三firstpass.mcf\n",progname);printf("%s-fvp62-dvp6vfw.dll-v\n",progname);printf("\tnif他的司机对话不工作的话,你可以尝试无一specifingfourcc,\n");printf("但thecompdata文件将不能用mencoder.\n");printf("司机办法规定,您必须指定至少-s,-c-o-v\n");printf("usagewithmencoder-ovcvfw-xvfwoptscodec=vp6vfw.dll:compdata=settings.mcf\n");intmain(intargc,char*argv[])(char*driver=null;char*fourcc=null;char*filename=null;unsignedcharmode=0;wchar_tdrvfile[max_path〕;hdrvrhdriver=null;intret=0;intc=-1,long_options_index=-1;if(argc"2)(help(argv[0]);ret=-1;gotocleanup;while((c=getopt_long(argc,argv,"高清:f:s:c:V型",long_options,&long_options_index))!=-1)(switch(c)(case'h':help(argv[0]);ret=0;gotocleanup;case'd':驾驶员=strdup(optarg);break;case'f':fourcc=strdup(optarg);if(strlen(optarg)!=4)保释("fourcc必须刚好4chars");break;case's':if(模式!=mode_none)保释("不争论");filename=strdup(optarg);mode=mode_save;break;case'c':if(模式!=mode_none)保释("不争论");filename=strdup(optarg);mode=mode_check;break;case'v':if(模式!=mode_none)保释("不争论");mode=mode_view;break;default:printf("错误论调!\n");如果(!(argc==optind)&&(模式!=mode_none)&&司机&&(filename|(mode==mode_view)))(help(argv[0]);gotocleanup;我f(!multibytetowidechar(cp_acp,0,驾驶员,-1,drvfile,max_path))保释("multibytetowidechar()failed\n");如果(!(hdriver=opendriver(drvfile,0,(fourcc)?((lparam)fourcc):0)))保释("opendriver()failed\n");如果(senddrivermessage(hdriver,icm_configure,-1,0)!=icerr_ok)保释("司机能源部sn't提供一个配置对话框");switch(mode)(casemode_check:如果(load_settings(hdriver,filename))保释("不能负荷设置文件");如果(senddrivermessage(hdriver,icm_configure,0,0)!=icerr_ok)保释("icm_configure失败");break;案例mode_save:如果(senddrivermessage(hdriver,icm_configure,0,0)!=icerr_ok)保释("icm_configure失败");如果(save_settings(hdriver,filename))保释("救不了设定文件");break;案例mode_view:如果(派出drivermessage(hdriver,icm_configure,0,0)!=icerr_ok)保释("icm_configure失败");break;默认:保释("这是不应该发生的:)");)cleanup:如果(司机)自由(驱动r);如果(fourcc)自由(fourcc);if(filename)free(filename);如果(hdriver)closedriver(hdriver,0,0);returnret; </span>