Two auxiliary tools for Latex writing: statistics Chinese characters and PDF documents in Acrobat

xiaoxiao2021-03-06  64

Latex does not bring a number of Chinese character statistics as Word, plus many control characters in the Latex source file, and you cannot know how many Chinese characters in which the file size is known. To this end, I wrote a gadget of a statistical Chinese character with CWC, which is CWC, which is Chinese Word Counter. This program only uses the Windows API using the count_files () function, which is slightly modified to port under Linux / UNIX. #include #include #include int total = 0; // Total Chinese Characters // Unicode Version Word Countervoid Word_count_u (file * pf) {INT W = 0, B = 2; WINT_T C;

While ((c = getwc (pf))! = weof) {b = 2; // Byte Count if (c> 127) {// Chinese character W ; // char count}} printf ("% 10D / t % 10D / N ", W, B); Total = W;} // Word Countervoid Word_count (const char * file) {INT W = 0, B = 0; INT C; int uncode = 0; file * pf = FOPEN (File, "RB"); if (null == pf) {return;} printf ("% 20s:", file); // Judgment whether it is a Unicode file IF ((c = getc (pf)) == 0xFF) {INT CC; IF ((cc = getc (pf)) == 0xfe) {unicode = 1; Printf ("Unicode"); Word_Count_u (PF);} else {fseek (PF, 0, seet);} } Else {UNGETC (C, PF);} if (! Unicode) {printf (""); while ((c = getc (pf))! = EOF) {b ; // Byte Count if (c> 127) {// Chinese characters W ; // char count b ; // Each Chinese character accounts for two bytes of byte IF ((c = getc (pf)) == EOF) B Reak;}} Printf ("% 10D / T% 10D / N", W, B); Total = W;} fclose (PF);

void count_files (const char * file) {WIN32_FIND_DATA FindFileData; HANDLE hFind = FindFirstFile (file, & FindFileData); if (INVALID_HANDLE_VALUE == hFind) {fprintf (stderr, "Can not find% s / n", file); return; }

do {if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) {continue;} if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {// do nothing} else {word_count (FindFileData.cFileName);}} while (FindNextFile (hFind, & FindFileData));

Findclose (HFIND);

INT Main (int Argc, char * argv []) {if (1 == argc) {// default: count all .tex and .txt files in current dir count_files ("*. tex"); count_files ("*. TXT ");} else {// get filenames from Command line arguments while (--arc> 0) {count_files (argv [argc]);}}}}} printf (" Total:% D ", Total); Return 0;} Another common problem is that when you generate a PDF file with DVIPDFM, you often forget to close this file in Acrobat, causing the following error tips: E: / Projects / SlidewindowReport> DVIPDFM Slidewindow

Slidewindow.dvi -> slidewindow.pdf

Unable to open slidewindow.pdf

Output file removed. I wrote a gadget that dedicated to shutting down the PDF file in Acrobat, named closepdf, the principle tells Acrobat through DDE to close a PDF file. This gadget is inspired by WINEDT automatic shutdown. (I track its macro code I know how to use DDE Control Acrobat), code is changed from MSDN. I don't understand DDE, but this does not hinder the normal work of the program :) With this gadget, I can write a Batch File to build and read the PDF file: Rem this is m.batlatex% 1Latex% 1Closepdf% 1. PDFDVIPDFM% 1% 2% 3% 4% 5Start% 1.pdf code as follows: // Close The user specified PDF file in Acrobat Reader // Ref. Microsoft Knowledge Base Article - 279721 // HOWTO: USE DYNAMIC DATA Exchange (DDE) with Word and Excel from Visual C // modified by Solstice 2004/01/2 # define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers # define STRICT # include #include #include < Stdio.h> #include #include

HDDedata Callback Ddecallback (uint utype, // transaction type. Uint Ufmt, // clipboard data format. Hsz hsz hsz1, // handle to a string. HSZ HSZ2, // Handle To a string HDATA, // Handle To A Global Memory Object. DWord Dwdata1, // Transaction-Specific Data. DWORD DWDATA2 / / TRANSACTION-Specific Data. {RETURN 0;}

void DDEExecute (DWORD idInst, HCONV hConv, char * szCommand) {HDDEDATA hData = DdeCreateDataHandle (idInst, (LPBYTE) szCommand, lstrlen (szCommand) 1, 0, NULL, CF_TEXT, 0); if (hData == NULL) { Printf ("Command Failed:% S / N", SZCommand;} else {DDECLIENTTRANSACTION ((lpbyte) HDATA, 0xFfffff, HCONV, 0L, 0, Xtyp_execute, Timeout_async, NULL);}}

void DDERequest (DWORD idInst, HCONV hConv, char * szItem, char * sDesc) {HSZ hszItem = DdeCreateStringHandle (idInst, szItem, 0); HDDEDATA hData = DdeClientTransaction (NULL, 0, hConv, hszItem, CF_TEXT, XTYP_REQUEST, 5000, NULL ); If (hdata == null) {Printf ("Request Failed:% S / N", Szitem);} else {char szresult [255]; DdegetData (HData, (unsigned char *) szResult, 255, 0); Printf ("% s% s / n", sdesc, szResult);}} void ddepoke (DWORD IDINST, HCONV HCONV, CHAR * SZITEM, CHAR * SZDATA) {HSZ HSZITEM = DDECREATESTRINGHANDLE (Idinst, Szitem, 0); DDECLIENTTRANSACTION (Lpbyte) SZDATA, (DWORD) (DWORD), HCONV, HSZITEM, CF_TEXT, XTYP_POKE, 3000, NULL; DDEFREESTRINGHANDE (IDInst, hszitem);}

int get_error (const char * filename) {HANDLE hFile = CreateFile (filename, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (INVALID_HANDLE_VALUE == hFile) {return GetLastError ();} else {CloseHandle (hFile); Return 0;}}}

Bool is_file_locked (const char * filename) {return (get_error (filename) == 32);

BOOL IS_FILE_EXISTS (const char * filename) {return (get_error (filename)! = 2);

INT Main (int Argc, char * argv []) {char SZAPP [] = "acroew"; char sztopic [] = "control"; char scloseall [] = "[closeallDocs ()]"; char full_file_name [max_path]; Const char * file_to_close = argv [1]; if (argc == 1) {// Close All PDF files} else {// close the specified file if (! is_file_exists) {printf ("% s doesn't EXISTS./N ", file_to_close); RETURN 1;} IF (is_file_locked (file_to_close)) {Printf ("% s is open, trying to close it ... / n ", file_to_close);} else {printf ("% S is closed./n ", file_to_close); return 0;} assert (getFullPathname (file_to_close, sizeof (full_file_name), full_file_name, null> 0); // printf (" full name: / "% s /" ", full_file_name);} //[docopen (""%p/%n.pdf")] //[docclose(""%p/%n.pdf"")]//dde initialization dword idinst = 0 Uint Ireturn; IReturn = Ddeinitialize (& iDinst, (pfncallback) DDECALLBACK, AppClass_Standard | AppCMD_Clientonly, 0); if (IReturn! = DMLERR_NO_ERROR) {Printf ("DDE Initialization Failed: 0x% 04x / N", Ireturn); SLEEP (1500); Return 0;}

// DDE Connect to Server using given AppName and topic HSZ hszApp, hszTopic;. HCONV hConv; hszApp = DdeCreateStringHandle (idInst, szApp, 0); hszTopic = DdeCreateStringHandle (idInst, szTopic, 0); hConv = DdeConnect (idInst, hszApp, hszTopic, NULL); DdeFreeStringHandle (idInst, hszApp); DdeFreeStringHandle (idInst, hszTopic); if (hConv == NULL) {printf ( "DDE Connection Failed./n"); Sleep (500); DdeUninitialize (idInst); return 0;} else {printf ("DDE Connection To Acrobat Reader Succeed./N"); Sleep (50);} if (argc == 1) {// Close All PDF Files // Execute Commands / Requests Specific To The DDE Server. Ddeexecute (IDINST, HCONV, SZCLOSEALL); Printf ("Closing All Pdf Documents ... / N); SLEEP (50);} else {// close the specified file char cmd_buf [MAX_PATH 100]; ///// [Docopen (""% p /% n.pdf ")] //[docclose (""%p/%n.pdf")] Printf ("Closing% S / N", Full_File_Name); Snprintf (cmd_buf SIZEOF cmd_buf), "[Docopen (/"% s / ")]", full_file_name); Ddeexecute (iDinst, hconv, cmd_buf); SLEEP (50); Snprintf (cmd_buf, sizeof (cmd_buf), "[DOCCLOSE (/"% S / ")]", full_file_name); DdeExecute (IDINST, HCONV, CMD_BUF); Sleep (50);} // DDE Disconnect and Uninitialize. Ddedisconnect (HCONV); DdeunInitialize (iDinst); if (argc == 1) { // Close All PDF files return (0);

转载请注明原文地址:https://www.9cbs.com/read-87208.html

New Post(0)