From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#2947: 23.0.91; font-lock-mode will hang emacs on this file (both on Windows/Linux) Date: Fri, 10 Apr 2009 13:50:19 -0400 Message-ID: References: <83prflkrhk.fsf@borqs.com> Reply-To: Stefan Monnier , 2947@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1239386687 16455 80.91.229.12 (10 Apr 2009 18:04:47 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 10 Apr 2009 18:04:47 +0000 (UTC) Cc: 2947@emacsbugs.donarmstrong.com To: Bao Haojun Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Apr 10 20:06:04 2009 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LsL6q-0001F2-V3 for geb-bug-gnu-emacs@m.gmane.org; Fri, 10 Apr 2009 20:05:54 +0200 Original-Received: from localhost ([127.0.0.1]:43067 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LsL5S-0006RI-6M for geb-bug-gnu-emacs@m.gmane.org; Fri, 10 Apr 2009 14:04:22 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LsL55-0006Ed-2l for bug-gnu-emacs@gnu.org; Fri, 10 Apr 2009 14:03:59 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LsL50-0006BK-3p for bug-gnu-emacs@gnu.org; Fri, 10 Apr 2009 14:03:58 -0400 Original-Received: from [199.232.76.173] (port=43695 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LsL4z-0006B4-SC for bug-gnu-emacs@gnu.org; Fri, 10 Apr 2009 14:03:53 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:39692) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LsL4y-0003H4-Ny for bug-gnu-emacs@gnu.org; Fri, 10 Apr 2009 14:03:53 -0400 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id n3AI3neW027433; Fri, 10 Apr 2009 11:03:50 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.13.8/8.13.8/Submit) id n3AHt5x3024521; Fri, 10 Apr 2009 10:55:05 -0700 X-Loop: owner@emacsbugs.donarmstrong.com Resent-From: Stefan Monnier Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Fri, 10 Apr 2009 17:55:05 +0000 Resent-Message-ID: Resent-Sender: owner@emacsbugs.donarmstrong.com X-Emacs-PR-Message: followup 2947 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Original-Received: via spool by 2947-submit@emacsbugs.donarmstrong.com id=B2947.123938587224030 (code B ref 2947); Fri, 10 Apr 2009 17:55:05 +0000 Original-Received: (at 2947) by emacsbugs.donarmstrong.com; 10 Apr 2009 17:51:12 +0000 X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. Original-Received: from ironport2-out.teksavvy.com (ironport2-out.teksavvy.com [206.248.154.182]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id n3AHoPYY023934; Fri, 10 Apr 2009 10:50:27 -0700 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkIGACMk30lLd+7D/2dsb2JhbACBUsoOgi2BTgaFFA X-IronPort-AV: E=Sophos;i="4.40,168,1238990400"; d="scan'208";a="36879391" Original-Received: from 75-119-238-195.dsl.teksavvy.com (HELO pastel.home) ([75.119.238.195]) by ironport2-out.teksavvy.com with ESMTP; 10 Apr 2009 13:50:19 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id 81246E9B48; Fri, 10 Apr 2009 13:50:19 -0400 (EDT) In-Reply-To: <83prflkrhk.fsf@borqs.com> (Bao Haojun's message of "Fri, 10 Apr 2009 13:27:51 +0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.92 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Resent-Date: Fri, 10 Apr 2009 14:03:58 -0400 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:27065 Archived-At: reassign 2947 emacs,cc-mode thanks > The file is attached, the offending character is the last `"' > character on line 117: > {"get micco", MICCO_TEST, "BB>", "0x1", "}, > If I run M-x font-lock-mode, Emacs will hang. I have also tested on > Linux Emacs. ^^^^^ [ Emacs does not run on a bare Linux kernel. Please call the system GNU/Linux. ] IIUC the file is opened in c++-mode, right? If so, it looks like a pathological regexp (or something similar) in cc-mode. Alan, can you take a look at it? Stefan > In GNU Emacs 23.0.91.1 (i386-mingw-nt5.1.2600) > of 2009-02-27 on SOFT-MJASON > Windowing system distributor `Microsoft Corp.', version 5.1.2600 > configured using `configure --with-gcc (3.4)' > Important settings: > value of $LC_ALL: nil > value of $LC_COLLATE: nil > value of $LC_CTYPE: nil > value of $LC_MESSAGES: nil > value of $LC_MONETARY: nil > value of $LC_NUMERIC: nil > value of $LC_TIME: nil > value of $LANG: CHS > value of $XMODIFIERS: nil > locale-coding-system: cp936 > default-enable-multibyte-characters: t > Major mode: C++/l > Minor modes in effect: > auto-image-file-mode: t > shell-dirtrack-mode: t > mouse-wheel-mode: t > file-name-shadow-mode: t > blink-cursor-mode: t > global-auto-composition-mode: t > auto-composition-mode: t > auto-encryption-mode: t > auto-compression-mode: t > line-number-mode: t > transient-mark-mode: t > abbrev-mode: t > Recent input: > C-x C-f s r c / c l i e n=20 > g a l c j s =20 > c l i M-x M-p C-k f o n t l o =20 > m o C-e C-b C-b " C-x C-s M-x C-g M-x=20 > g l o b f o n M-x r e p o r =20 > > Recent messages: > Loading paren...done > Loading q:/.session...done > For information about GNU Emacs and the GNU system, type C-h C-a. > Searching for `cli'.... > Loading vc-svn...done > Font-Lock mode disabled > Saving file q:/src/alchemy/JSC-fork-dll/AlchemyLib/cli.cpp... > Wrote q:/src/alchemy/JSC-fork-dll/AlchemyLib/cli.cpp > Quit > Global-Font-Lock mode disabled > #include "stdafx.h" > #include "alchemy_internal.h" > #include > #include "cli.h" > #define ENABLE_BHJDEBUG > #include "bhjdebug.h"=20 > typedef enum > { > FACTORY_ID =3D 0x001, > GPIO_TEST =3D 0x003, > REGISTER_TEST =3D 0x004, > ADC_TEST =3D 0x005, > REBOOT_TEST =3D 0x006, > CAMERA_TEST =3D 0x007, > BLUETOOTH_TEST =3D 0x008, > TESTINFO =3D 0x009, > ATPARSER_TEST =3D 0x00a, > VIBRATOR_TEST =3D 0x00b, > POWERREASON_TEST=3D0x00c, > VOLTAGE_TEST =3D 0x00d, /*get real voltage by ADC */ > TEMPRATURE_TEST =3D 0x00e, /*get real temprature by ADC */ > CHARGETYPE_TEST =3D0x00f, > GSENSOR_TEST =3D 0x010, > MICCO_TEST =3D 0x011, > LCDBACK_TEST =3D 0x012, > KEYBACK_TEST =3D 0x013, > TOUCH_POINT =3D0x014, > KEY_INPUT =3D 0x015, > ONLY_Key =3D 0x031, > LGSENSOR_TEST =3D 0x01c, > GSENSOR_INFO =3D 0x01d, =09 > /* DDR test commands */ > Ddr_TEST =3D 0x01f, > /* LCD test commands */ > LCD_TEST =3D 0x20, > /* T-FLASH card detect*/ > CARD_TEST =3D0x021,=20=20 > /* charge status */ > CHARGESTATUS_TEST =3D 0x022,=20 =20=20=20=20 > /* MAT FILE Read AND write */ > MAT_TEST =3D 0x023 , =09 > /*audio hardware test */ > AUDIO_TEST =3D 0x024, =20=20=20=20=20 =20=20=20=20 > /* ADC calibration &NVM block operation related test commands*/ > CALI_TEMP =3D 0x016, /*only operation on filesystem file*/ > CALI_VOLT =3D 0x017, /*only operation on filesystem file*/ > NVM_TEST =3D 0X018, > VOLT_TEST =3D 0x019, /*read /write from filesystem to NVM block*/ > TEMP_TEST =3D 0x01a, /*read /write from filesystem to NVM block*/ > RF_TEST =3D 0x01b, /*read /write from filesystem to NVM block*/ > TESTINFO_TEST =3D0x025,/*read /write from filesystem to NVM block*/ > FACTORYID_TEST=3D0x026,/*read /write from filesystem to NVM block*/ > MATFLAG_TEST=3D0x027,/*read /write from filesystem to NVM block*/ =20=20=20=20 > /*touch panel test */ > PANEL_TEST =3D 0x028, > /*empty test */ > EMPTY_TEST =3D 0x029, =20=20=20 > /* bluetooth test commands */ > BT_TEST =3D 0x050, > BTNVM_TEST=3D 0x051, > BT_INQUIRE=3D 0x052, > BT_TESTMODE =3D0x053, > BT_KILL=3D0x054,//kill the "/system/bin/hciattach" process after ente= r into BT Test Mode /BTINQUIRE=20 > /*camera test commands */ > CAMERA_PREVIEW =3D 0x060, > LAUNCH_CAMERA =3D 0x61, > I2C_TEST =3D 0x01e, =20=20=20=20 > /*CMMB test commands */ > IF101_TEST=3D 0x070,=20=20=20=20 > INNO_DEVICE=3D 0x071, /*enter or exit CMMB test mode*/ > Signallock_TEST =3D 0x72, > Sensitive_TEST =3D 0x73, > IF101_SPI_TEST =3D 0x74, > IF101_SET_FREQ =3D 0x75, > LAUNCH_TV =3D 0x76, > /* GPS test commands */=20 > GPS_TEST =3D 0x80, > GPS_LOCATION=3D0x81, > GPS_MESSAGE=3D0x82,/*only get NEMA Message*/ > GPS_LOCA_MESSAGE=3D0x83,/*only get Location Message*/ > GPS_CHANGE_MODE=3D0x84,/*Change between hot mode and code mode*/ =20=20 > /* SPARK */ > SPARK_KEY=3D0x90,/*TEST KEY INPUT*/ > /* Key Monitor */ > KEY_MONITOR=3D0x91, > /* Sensor Monitor */ > SENSOR_MONITOR=3D0x92, > /* Set/Get LPR SMS report flag */ > SMS_FLAG =3D0x93, > /* Set/Get LPR livetime period */ > LIVETIME_PERIOD =3D 0x94, > /* Set/Get EFEM feature flag */ > EFEM_FLAG =3D0x95, > DIAG_LAUNCH=3D0x96,=09 > GET_RDNVM =3D0x9a, > DIAG_EXT_INTERFACE=3D0x9b, > /*to set /get element config value */ > NVM_Element=3D0x9c, > /*to set /get phase data : */ > NVM_PHASE =3D0x9d, > /*Common set/get Bit config element value*/ > NVM_BITCONFIG =3D0x9e,=20 > /* Version */ > VERSION =3D 0x039, =20=20=20=20 > /* bp only handler */ > BP_ONLY =3D 0xFFFF > } TC_AP_FSM_EVENT_OPCODE_T; > typedef unsigned char u8; > typedef unsigned short u16; > typedef struct{ > const char *cmdName; > int opCode; > const char *inputSpec; // datatype: BHIOoF, how: <>*!=20 > const char *fixedInput; > const char *description; =09 > } testCmd_T; > //< means from the fixedInput,=20 > //> means from user provided input,=20 > //! means arbitrary value is acceptable, so we just use 0,=20 > //* means fill with a string > static testCmd_T cmdMap[] =3D { > {"version", VERSION, "B<", "0x12", "Read software version of the phone"}, > {"get factory_id", FACTORY_ID, "B<", "0x11", "Read FactoryId of the phon= e"}, > {"set factory_id", FACTORY_ID, "B {"atCommand", ATPARSER_TEST, "B*", "", "Test an AT command" }, > {"get gpio", GPIO_TEST, "BB!", "0x1", "Get GPIO, the u16 argument is = the GPIO number"}, > {"set gpio", GPIO_TEST, "BB>", "0x2",=20 > "Set GPIO, the u16 is GPIO number, the u8 is GPIO setting\n" > "the meaning of bit 7-0:\n" > " level : 1, //0:low,1:High\n" > " in_out: 1, //0:input, 1:output\n" > " pullup: 1, //0:no pullup,1:pullup\n" > " pulldown: 1, //0:no pulldown,1:pulldown\n" > " tri_state: 1, //0:anit_tristate,1:tristate\n" > " reserved: 3;\n" > }, > {"get register", REGISTER_TEST, "BI!", "0x1", "Read register value, u= 32 is register number. Use with caution!"}, > {"set register", REGISTER_TEST, "BI>", "0x2", "Write register, first = u32 is register number, second is value"}, > {"get adc", ADC_TEST, "B>H!", "", "Read A/D converter value, u8 is AD nu= mber" }, > {"reboot poweroff", REBOOT_TEST, "B<", "0x0", "reboot to poweroff mode"}, > {"reboot factory", REBOOT_TEST, "B<", "0x1" "reboot to factory mode (min= imal applications will start, so boot/test is faster)"}, > {"reboot normal", REBOOT_TEST, "B<", "0x2", "reboot, the `Normal' reboot= "}, > {"reboot flash", REBOOT_TEST, "B<", "0x3", "reboot to flash mode"}, > //{"camera test", //??? > {"launch camera", LAUNCH_CAMERA, "", "", "lauch camera"}, > //{"bluetooth test", //??? > //{"get info", TESTINFO, "B<", "0x11"}, //??? > //{"set info", TESTINFO, "B {"get gsensor", GSENSOR_TEST, "BB!", "0x1", "get gravity sensor value= , u8 is the gsensor number"}, > {"set gsensor", GSENSOR_TEST, "BB>", "0x2", "set gsensor value, first= u8 is the gsensor number, second is value"}, > {"get micco", MICCO_TEST, "BB>", "0x1", "}, > {"set micco", MICCO_TEST, "BB>", "0x2"}, > {"vibrator on", VIBRATOR_TEST, "B<", "0x1"}, > {"vibrator off", VIBRATOR_TEST, "B<", "0x2"}, > //{"at test" //bhj: don't know what this means > {"get power reason", POWERREASON_TEST, "", ""}, > {"get chargetype", CHARGETYPE_TEST, "B<", "0x1"}, > {"set chargetype", CHARGETYPE_TEST, "B", "0x2"}, > {"get manual voltage", VOLTAGE_TEST, "B<", "0x0"}, > {"get auto voltage", VOLTAGE_TEST, "B<", "0x4"}, > {"get manual temperature", TEMPRATURE_TEST, "B<", "0x1"},//0x0?=20 > {"get auto temperature", TEMPRATURE_TEST, "B<", "0x5"}, > {"get lcdbl", LCDBACK_TEST, "B", "0x1"}, > {"set lcdbl", LCDBACK_TEST, "B", "0x2"}, > {"get keybl", KEYBACK_TEST, "B", "0x1"}, > {"set keybl", KEYBACK_TEST, "B", "0x2"}, > {"test touch", TOUCH_POINT, "", ""}, > {"test keyinput",ONLY_Key,"",""}, > {"get lprflag", SMS_FLAG, "B<", "0x1"}, > {"set lprflag", SMS_FLAG, "B", "0x2"}, > {"get lprtime", LIVETIME_PERIOD, "B<", "0x1"}, > {"set lprtime", LIVETIME_PERIOD, "B", "0x2"}, > {"get efemflag", EFEM_FLAG, "B<", "0x1"}, > {"set efemflag", EFEM_FLAG, "B", "0x2"}, > {"get cali temperature",CALI_TEMP,"B<","0x1"},//add by Jason from here > {"get cali voltage",CALI_VOLT,"B<","0x1"}, > {"set cali voltage",CALI_VOLT,"B {"store volt",VOLT_TEST,"B<","0x1"}, > {"load volt",VOLT_TEST,"B<","0x2"}, > {"store temp",TEMP_TEST,"B<","0x1"}, > {"load temp",TEMP_TEST,"B<","0x2"}, > {"store RF",RF_TEST,"B<","0x1"}, > {"load RF",RF_TEST,"B<","0x2"}, > {"store testinfo",TESTINFO_TEST,"B<","0x1"}, > {"load testinfo",TESTINFO_TEST,"B<","0x2"}, > {"store factoryid",FACTORYID_TEST,"B<","0x1"}, > {"load factoryid",FACTORYID_TEST,"B<","0x2"}, > {"store MATflag",MATFLAG_TEST,"B<","0x1"}, > {"load MATflag",MATFLAG_TEST,"B<","0x2"}, > {"camera preview on",CAMERA_PREVIEW,"B<","0x1"}, > {"camera preview off",CAMERA_PREVIEW,"B<","0x2"}, > {"get sensor",LGSENSOR_TEST,"B<","0x1"}, > {"i2c test",I2C_TEST,"",""}, > {"if101 test",IF101_TEST,"",""}, > {"read bt",BT_TEST,"B<","0x1"}, > {"write bt",BT_TEST,"B {"store btnvm",BTNVM_TEST,"B {"load btnvm",BTNVM_TEST,"B<","0x2"}, > {"bt inquire",BT_INQUIRE,"",""}, > {"bt testmode",BT_TESTMODE,"",""}, > {"bt kill",BT_KILL,"",""},//ljs:not find the definition > {"launch tv",LAUNCH_TV,"",""}, > {"ddr test",Ddr_TEST,"",""}, > {"gps test",GPS_TEST,"B>",""}, > {"lcd test",LCD_TEST,"B>",""}, > {"card detect",CARD_TEST,"B>",""}, > {"charge status",CHARGESTATUS_TEST,"B>",""}, > {"audio test",AUDIO_TEST,"B>",""}, > //data: 0x01: AUDIO_SD_PLAY > // 0x02: AUDIO_MICRO_TEST > // 0x03: AUDIO_EAR_TEST > {"save rd",GET_RDNVM,"B","0x1"}, > {"get diag_en",DIAG_LAUNCH,"B<","0x1"}, > {"set diag_en",DIAG_LAUNCH,"B","0x2"}, > {"get diag_intf",DIAG_EXT_INTERFACE,"B<","0x1"}, > {"set diag_intf",DIAG_EXT_INTERFACE,"B","0x2"}, > {"get element",NVM_Element,"I>B<","0x1"}, > {"set element",NVM_Element,"I>B {"get phase",NVM_PHASE,"I>B<","0x1"}, > {"set phase",NVM_PHASE,"I>B","0x2"}, > {"get ap_panic_report",NVM_BITCONFIG,"I>B<","0x1"}, > {"set ap_panic_report",NVM_BITCONFIG,"I>B","0x2"}, > {"opcode", -1, "o>", ""}, > {"reliable data", 0x97, "F>", ""}, > {NULL, 0, NULL, NULL}, > }; > static BOOL notOptionalCode(char c) > { > return (c!=3D'*' && c!=3D'?'); > } > static BOOL isOptionalCode(char c) > { > return !notOptionalCode(c); > } > static BOOL isSingleOptional(char c) > { > return c=3D=3D'?'; > } > static BOOL isMultiOptional(char c) > { > return c=3D=3D'*'; > } > static unsigned long getLong(CString& strInput) > { > const char *s =3D strInput.GetBufferSetLength(strInput.GetLength()); > char *firstInvalid =3D NULL; =09 > long dataH =3D strtol(s, &firstInvalid, 0); > strInput.ReleaseBuffer(); > strInput.Delete(0, firstInvalid-s); > strInput.TrimLeft(); > return (unsigned long) dataH; > } > static int getLongCheck(CString& strInput, unsigned long& outLong)=20 > { > outLong =3D 0; =09 > strInput.TrimLeft(); > strInput.TrimRight(); > if (strInput.IsEmpty()) { > return -1; > } > int len =3D strInput.GetLength(); > outLong =3D (unsigned long)getLong(strInput); > if (len =3D=3D strInput.GetLength()) { > return -1; > } > return 0; > } > static int getB(CString& strInput, CU8Array& dataArr) > { > unsigned long outLong =3D 0; > if (getLongCheck(strInput, outLong) < 0) { > return -1; > } > unsigned char data =3D (unsigned char)outLong; > dataArr.Add(data); > return 0; > } > //'H' stands for a short > static int getH(CString& strInput, CU8Array& dataArr) > { > unsigned long outLong =3D 0; > if (getLongCheck(strInput, outLong) < 0) { > return -1; > } > unsigned short data =3D (unsigned short) outLong; > //big endian or little endian? > dataArr.Add(data&0xff); > dataArr.Add(data>>8); > return 0; > } > static int getI(CString& strInput, CU8Array& dataArr) > { > unsigned long outLong =3D 0; > if (getLongCheck(strInput, outLong) < 0) { > return -1; > } > unsigned int data =3D (unsigned int)outLong; > dataArr.Add(data&0xff); //=E8=8E=B7=E5=8F=96int=E7=9A=84=E4=BD=8E=E4= =BD=8D=E5=AD=97=E8=8A=82 > dataArr.Add((data>>8) & 0xff); //=E8=8E=B7=E5=8F=96int=E7=9A=84=E7=AC=AC= =E4=BA=8C=E4=B8=AA=E5=AD=97=E8=8A=82=09 > dataArr.Add((data>>16) & 0xff); //=E8=8E=B7=E5=8F=96int=E7=9A=84=E7=AC= =AC=E4=B8=89=E4=B8=AA=E5=AD=97=E8=8A=82 > dataArr.Add((data>>24) &0xff); //=E8=8E=B7=E5=8F=96int=E7=9A=84=E7=AC=AC= =E5=9B=9B=E4=B8=AA=E5=AD=97=E8=8A=82 > return 0; > } > static int getF(CString& strInput, CU8Array& dataArr) > { > strInput.TrimLeft(); > strInput.TrimRight(); > FILE* fp =3D fopen(strInput, "rb"); > if (fp =3D=3D NULL) { > urgTrace("Error: %s open failed", (const char *)strInput); > return -1; > } > fseek(fp, 0, SEEK_END); =09 > DWORD dwLength =3D ftell(fp); > rewind(fp); > char *buff =3D (char *)calloc(dwLength, 1); > DWORD numRead =3D 0; =09 > for (;;) { > numRead +=3D fread(buff+numRead, 1, dwLength, fp); > if (numRead =3D=3D dwLength) > break; > } =09 > ASSERT(numRead =3D=3D dwLength); > for (DWORD i=3D0; i dataArr.Add(buff[i]); > } > free(buff); > fclose(fp); > return 0; > } > #define AppendFormat(s, fmt) do { \ > CString tmp_asfd; \ > tmp_asfd.Format fmt; \ > s+=3Dtmp_asfd; \ > } while (0) > static CString getFormat(const char *dC /* i.e., inputSpec, such as "BB*"= */) > { > CString format; > for (int i=3D0; dC[i]; i++) { > if (dC[i]=3D=3D'B' && notOptionalCode(dC[i+1])) { > continue; > } else if (dC[i]=3D=3D'B' && isMultiOptional(dC[i+1])) { > i++; > format +=3D "[string] "; > } else if (dC[i]=3D=3D'H' && isSingleOptional(dC[i+1])) { > i++; > format +=3D "[uint16] "; > } else if (dC[i]=3D=3D'I' && isSingleOptional(dC[i+1])) { > i++; > format +=3D "[uint32] "; > } else if (dC[i]=3D=3D'B' && isSingleOptional(dC[i+1])) { > i++; > format +=3D "[uint8] "; > } else if (dC[i]=3D=3D'O' && notOptionalCode(dC[i+1])) { > format +=3D "[uint32 (as opcode)] [uint8]... "; > } else if (dC[i]=3D=3D'F' && notOptionalCode(dC[i+1])) { > format +=3D "[filename] "; > } else if (dC[i]=3D=3D'o' && notOptionalCode(dC[i+1])) { > format +=3D "[uint8]... "; > } > } > if (format.IsEmpty()) { > format +=3D "no args"; > } > format +=3D "\r\n"; > return format; > } > static void commands() > { > CString helpStr("\r\nCommands:\r\n--------------------------------\r\n\r= \n"); > for (int i=3D0; cmdMap[i].cmdName!=3DNULL; i++) { > CString cmdName(cmdMap[i].cmdName); > AppendFormat(helpStr, ("%-25s : " > "opcode 0x%04x : " > "%s", cmdName,=20 > (unsigned short)cmdMap[i].opCode,=20 > getFormat(cmdMap[i].inputSpec))); > } > urgTrace("%s", helpStr); =09 > } > static void help() > { > CString helpStr("\r\nHelp:\r\n--------------------------------\r\n\r\n" > "You can type the following to get more infomation:,\r\n" > "\r\n" > " help: dislay this help\r\n" > " todo: display to-do in this tool\r\n" > " bugs: display bugs/defects known\r\n" > " commands: display a list of available commands\r\n" > "\r\n" > "When you type `commands`, the commands are displayed as `Command : Ar= gs`,\r\n" > "Leading and trailing spaces in a command is ignored,\r\n" > " for e.g., `set keybl 255` is equal to ` set keybl 255 `\r\n" > "but, space in a command is not,\r\n" > " for e.g., `get keybl` is ok, but `get keybl` is not a valid comman= d\r\n" > "for those command that want one or more u8/u16/u32 argument, \r\n" > "if none or less that required argument is supplied, a default 0 is us= ed\r\n" > " for e.g., `set register 0x33 0x44` takes 2 args\r\n" > " 0x33 is register number, 0x44 is the value, \r\n" > " i.e., register 0x33 will be set to 68 (decimal value of 0x44) \r\n" > " But, if you run `set register`, then register 0 will be set to 0\r\= n" > "And, you can use 0xf/017/15 to mean the same INT, 15."); =09=09=09 > urgTrace("%s", helpStr); > } > static void todo() > { > CString todoStr("\r\nTodo:\r\n--------------------------------\r\n\r\n" > " 1. make the interface more user-friendly\r\n" > " for e.g., get gpio should show if the i/o is pu/pd, etc.\r\n" > " 2. implement a better help system\r\n" > " 3. provide a means to clear or save the log to a file\r\n" > " 4. provide a means to save the commands executed to a file\r\n" > " 5. implement execution of commands from the saved commands file\r= \n" > " 6. fix bugs"); > urgTrace("%s", todoStr); > } > static void bugs() > { > CString bugsStr("\r\nBugs:\r\n--------------------------------\r\n\r\n" > " 1. connection is broken after you disconnect the usb cable\r\n" > " and must restart the application to reconnect\r\n" > " 2. you must connect the usb cable before you start the applicatio= n\r\n" > " 3. many other bugs, some are even undiscovered yet\r\n" > " Please help report bugs/suggestions to haojun.bao@borqs.com"); > urgTrace("%s", bugsStr); > } > static void printResult(CU8Array& result) > { > CString recvTrace("\""); > if (result.GetSize()=3D=3D0) { > return; > } > for (int k=3D0; k if (isprint(result[k])) { > recvTrace +=3D result[k]; > } else { > CString tmp; > tmp.Format("\\x%02x", result[k]); > recvTrace +=3D tmp; > } > } > recvTrace+=3D'"'; > urgTrace("%s", recvTrace); > recvTrace =3D " in hex: "; > for (k=3D0; k CString tmp; > tmp.Format("0x%02x ", result[k]); > recvTrace +=3D tmp; > } > dbgTrace("%s", recvTrace); =09=09=09=09=09=09=09=09=20=20=20 > return; > } > static BOOL isFromUser(char where) > { > return where =3D=3D '>'; > } > static BOOL isFromFixed(char where) > { > return where =3D=3D '<'; > } > static BOOL isArbitrary(char where) > { > return where =3D=3D '!'; > } > static BOOL isMultiple(char where) > { > return where =3D=3D '*'; > } > static int getArg(CU8Array& dataArr, CString& strUserInput, CString& strF= ixedInput, char dataType, char where) > { > if (dataType =3D=3D 'B') { > if (isFromUser(where)) { > return getB(strUserInput, dataArr); > } else if (isFromFixed(where)) { > return getB(strFixedInput, dataArr); > } else if (isArbitrary(where)) { > return getB(CString("0"), dataArr); > } else if (isMultiple(where)) { //the rest of the user-input is consumed > for (int k=3D0; k dataArr.Add(strUserInput[k]); > } > strUserInput =3D ""; //empty user-input > return 0; > } > } else if (dataType =3D=3D 'H') { > if (isFromUser(where)) { > return getH(strUserInput, dataArr); > } else if (isFromFixed(where)) { > return getH(strFixedInput, dataArr); > } else if (isArbitrary(where)) { > return getH(CString("0"), dataArr); > } else { > urgTrace("Error: alchemy bug detected, code is %c %c", dataType, where= ); > return -1; > } > } else if (dataType =3D=3D 'I') { > if (isFromUser(where)) { > return getI(strUserInput, dataArr); > } else if (isFromFixed(where)) { > return getI(strFixedInput, dataArr); > } else if (isArbitrary(where)) { > return getI(CString("0"), dataArr); > } else { > urgTrace("Error: alchemy bug detected, code is %c %c", dataType, where= ); > return -1; > } > } else if (dataType =3D=3D 'o') { > strUserInput.TrimLeft(); > CString savedCommand =3D strUserInput; =09=09=09=09=09 > for (int k=3D0;;k++) { //infinite loop, k is only for debugging > if (strUserInput.IsEmpty()) { > break; > } > getB(strUserInput, dataArr); > if (strUserInput =3D=3D savedCommand) { > urgTrace("invalid arguments, `%s'", savedCommand); > return -1; > } > strUserInput.TrimLeft(); > savedCommand =3D strUserInput; > } =09=09 > return 0; > } else if (dataType =3D=3D 'F') { > if (!isFromUser(where)) { > urgTrace("Error: alchemy bug detected, code is %c %c", dataType, where= ); > }=09=09=09=09 > return getF(strUserInput, dataArr); > } else { > urgTrace("Error: alchemy bug detected, code is %c %c", dataType, where); > return -1; > } > return 0; > } > int cliCarryOut(const char *sCommand) > { > return cliCarryOut(CString(sCommand)); > } > int cliCarryOut(const CString& sCommand) > { > CU8Array result; > return cliCarryOut(sCommand, result); > } > //resolve the command send by IDC_EXEC_COMMAND > int cliCarryOut(const CString& sCommandConst, CU8Array& result) > { > if (alchemyInited =3D=3D FALSE) { > urgTrace("Must call InitAlchemyLib first!\n"); > return -1; > } > //we need to change the input string, so make a copy to remove the `cons= t' > CString sCommand =3D sCommandConst; > sCommand.TrimLeft(); > sCommand.TrimRight(); =09 > for (int i=3D0; cmdMap[i].cmdName; i++) { > if (sCommand.Find(cmdMap[i].cmdName) =3D=3D 0) { > const char *inputSpec =3D cmdMap[i].inputSpec; > const char *fixedInput =3D cmdMap[i].fixedInput; > int opcode =3D cmdMap[i].opCode; // this will change if cmd is "opcod= e" =09=09=09 > //so that only args to the cmd is in sCommand > sCommand.Delete(0, strlen(cmdMap[i].cmdName)); > sCommand.TrimLeft(); =09=09=09 > CString strUserInput =3D sCommand; > CString strFixedInput =3D fixedInput? fixedInput : ""; =09=09=09 > CU8Array dataArr; //empty at first > //handle opcode first: > if (opcode < 0) { > opcode =3D getLong(strUserInput); > } =09=09=09 > for (int j=3D0; inputSpec[j]; j=3Dj+2) { > int n =3D getArg(dataArr, strUserInput, strFixedInput, inputSpec[j], = inputSpec[j+1]); > if (n < 0) { > urgTrace("Error: don't know how to parse the input string:\n %s",= (const char*)sCommandConst); > } > }=20 > if (strUserInput.GetLength()) { > urgTrace("Error: argument parse failed, `%s' is remaining in the comm= and string", strUserInput); > return -1; > } > BYTE recv[1024] =3D {0}; > int nRecv =3D 0; > CString sendTrace("send: \"opCode "); > CString tmp; > tmp.Format("0x%08x,data: ", opcode); > sendTrace+=3Dtmp; > for (int k=3D0; k CString tmp; > tmp.Format("0x%02x ", dataArr[k]); > sendTrace+=3Dtmp; > } > if (dataArr.GetSize()>10) { > sendTrace+=3D"..."; > } > dbgTrace("%s", sendTrace); > int ret =3D getConnection()->UC_Do3rdCommand(opcode, > dataArr, > result, > cmdMap[i].cmdName); > printResult(result); > if (ret < 0) { > infoTrace("`%s`: failed!", cmdMap[i].cmdName); > return -1; > } else { > infoTrace("`%s`: success!", cmdMap[i].cmdName); > return 0; > } > } > } > if (sCommand.Find("help") =3D=3D 0) { > help(); > } else if (sCommand.Find("todo") =3D=3D 0) { > todo(); > } else if (sCommand.Find("bugs") =3D=3D 0) { > bugs(); > } else if (sCommand.Find("commands") =3D=3D 0) { > commands(); > } else { > urgTrace("%s", sCommand+=3D": unknown command"); > }=20 > return 0; > }