re-0.1.orig/0040755000000000001440000000000007066001215011605 5ustar rootusersre-0.1.orig/AUTHORS0100644000000000001440000000021007050300312012634 0ustar rootusersRussian Anywhere: Dmitri Livotov, http://now.at/dll , dll@peterlink.ru Tatiana Khachaturova, http://www.tarunz.org/~tx , tx@tarunz.org re-0.1.orig/COPYING0100644000000000001440000003543307037153153012654 0ustar rootusers GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS re-0.1.orig/ChangeLog0100644000000000001440000000015507051366023013362 0ustar rootusers[13-Feb-2000] version 0.1 Just first UNIX version. All decoding features from RE4.62 for Windows are ported.re-0.1.orig/INSTALL0100644000000000001440000000100107050301012012612 0ustar rootusersBasic Installation ================== These are generic installation instructions. run the "compile" script to compile Russian Anywhere sources After successfull compile, you'll get the executable "re" Now, you may copy it to /usr/bin (/usr/local/bin) to allow all users access Russian Anywhere or just leave somewhere inside your home directory if you do not have root rights. Run "re" without any options to print the usage information Compilers ========= c++ compiler should be used re-0.1.orig/README0100644000000000001440000001235207051366425012500 0ustar rootusers This is the Russian Anywhere port for UNIX. Version 0.1 (4.62 port) (c) 1999-2000, Dmitri Livotov, Tatiana Khachaturova Contents ========= 1. What is Russian Anywhere 2. How to compile and install 2.1 Requiriments 2.2 Compiling 2.3 Installing 3. How to use Russian Anywhere 4. Known bugs 5. Todo 6. Bug reports 7. Authors ====================================================================== 1. What is Russian Anywhere Russian Anywhere is a russian character decoding program. It allow transfer russian characters between different codepages. It's main purpose is to convert damaged russian e-mail messages to readable form and also may be used to convert files from/to known and unknown codepages. 2. How to compile and install 2.1 Requiriments Althought files have a ".c" extension, c++ compiler should be used (gcc or c will not work properly without modifying RE sources) 2.2 Compiling To compile just run the "compile" script. This will compile Russian Anywhere and you'll get the "re" executable. 2.3 Installing Copy "re" executable to any location you prefer (/usr/bin , /usr/local/bin or wherever you want. To run Russian Anywhere just type - re (Or /path/to/russian-anywhere/re , if you copied "re" to location which is not in PATH env. variable) 3. How to use Russian Anywhere The easiest way to convert some file into readable form (KOI-8), just type this: re ? K where : - unreadable file - resulting file ? - tells RE that source codepage is unknown and RE should analyze the file and determine the source codepage K - tells RE that destination codepage is KOI-8 Note: If you know, what is source codepage, you may use it instead of "?" option. For example, you want to convert letter.txt file which was written in Windows and so you know, that this file is in 1251 codepage: re letter.txt letter2.txt W K Now examine the letter2.txt - you should see russian symbols in KOI-8. Here is the know codepages list and their abbreviatures: W - Windows 1251 "_" - _xxe D - Dos "%" - %hex K - KOI-8 "\\" - \'hex L - Latin G - Graph_win I - Iso "<" - H - HEX + - +UTF7- S - ShiftKbrd C - C_MIC M - Mac Y - Y_c16 A - AFF Z - Z_c32 O - Odd(UTF8_1) F - F(UTF8_2) B - Base64 P - Pict E - Express N - N_Estl T - T-Html V - V_Vpp855 U - User X - X_sp "-" - -uue J - J_diff Run Russian Anywhere without any option and you'll get the help message. Also, you may read this message below: Russian Anywhere v0.1, 1999-2000, ver.0.1 (4.62 port), http//tx-tx.da.ru, http//now.at/dll usage: re options options: [-v][-E|-R|-N][-e|-s] -v - tells what is processing -n - don't tells what is processing (default) -E - converts all p,H from Russian to English -R - converts all p,H from English to Russian -N - lets all p,H Russian or English as in text (default) -e - converts all symbols 0x80 - 0xFF -s - converts only 64 symbols of Russian Alphabet (default) , - any from list (default - W,K): W - Windows "_" - _xxe D - Dos "%" - %hex K - KOI-8 "\\" - \'hex L - Latin G - Graph_win I - Iso "<" - H - HEX + - +UTF7- S - ShiftKbrd C - C_MIC M - Mac Y - Y_c16 A - AFF Z - Z_c32 O - Odd(UTF8_1) F - F(UTF8_2) B - Base64 P - Pict E - Express N - N_Estl T - T-Html V - V_Vpp855 U - User X - X_sp "-" - -uue J - J_diff if ="?" - try autoconvert For , only first symbol significant, case sensitive; autoconvert option disabled for =s or d. decrypt or encrypt file-from into file-to: cpi-from or cpi-to = "!", using arbitrary string in other cpi as passwd. : s(string) or d(dbf) or f(file), default-f : if file - convert text-file filename-from -> filename-to if dbf - convert all text fields in DBFfile filename-from -> filename-to if string - convert string and print result to screen (if string -- arg value not significant). : -u or -l or -s or none, default-none : if -u - load user cpi from file if -l - load new addcpi set from file if -s - save current addcpi set as file . 4. Known bugs 5. Todo - Know bugs fixes - GUI frontend for X, combined with the simple text editor 6. Bug reports Please report any found bugs to Dmitri Livotov - dll@peterlink.ru or Tatiana Khachaturova - tx@tarunz.org 7. Authors (c) 1998-2000 Dmitri Livotov, http://now.at/dll , dll@peterlink.ru (c) 1998-2000 Tatiana Khachaturova, http://tx-tx.da.ru , tx@tarunz.org Russian Anywhere for Unix uses GPL license. Please, find a copy of the GPL license in the "COPYING" file, included into this tar.gz archive. For comments, wishes, bug reports, etc regarding Russian Anywhere, please write to dll@peterlink.ru , tx@tarunz.org re-0.1.orig/TODO0100644000000000001440000000022407051366136012302 0ustar rootusersMain things to do: - Fix bugs from "Known Bugs" section of the README file and any other new bugs - GUI frontend for X with the simple text editor re-0.1.orig/compile0100755000000000001440000000021307051365717013172 0ustar rootusersc++ -s -O3 src/re_cmd.c src/ru32call.c src/ru32cp.c src/ru32var.c src/ru32lat.c src/ru32fi.c src/ru32au.c src/ru32mau.c src/ru32un.c -ore re-0.1.orig/re-0.1.lsm0100644000000000001440000000130707051370025013224 0ustar rootusersBegin3 Title: Russian Anywhere Version: 0.1 Entered-date: 13FEB2000 Description: An utility to convert russian texts between different codepages with source codepage autodetection feature. Russian Anywhere also supports multiple converted files. Keywords: RussianAnywhere decoder cyryllic codepages Author: dll@peterlink.ru (Dmitri Livotov), tx@tarunz.org (Tatiana Khachaturova) Maintained-by: dll@peterlink.ru (Dmitri Livotov) Primary-site: now.at/dll /eng/software.html 39K re-0.1.tar.gz 711 re-0.1.lsm Alternate-site: now.at/dll /rus/software.html Original-site: http://now.at/dll/eng/software.html Platforms: UNIX , should compile under almost all other OSes and platforms Copying-policy: GPL End re-0.1.orig/src/0040755000000000001440000000000007050277654012413 5ustar rootusersre-0.1.orig/src/re_cmd.c0100644000000000001440000000413107051365473014002 0ustar rootusers /***** re_cmd.c *****/ #include #include #include #include "ru32un.h" #include "ru32call.h" main(int argc, char* argv[]) { // usage: // re_cmd [opts] // opts: -[v|n][E|R|N][e|s]\n", // : s or d(dbf) or f, default-f> // : -u,-l,-s : // load user cpi, load new addcpi list, save addcpi list. char fnfrom[81]="noname.txt",fnto[81]="noname2.txt",userfile[81], cpifrom[61]="Win",cpito[61]="Koi"; int cp1=-1,cp2=-1,isExt=false,isVer=true,isopt =0; char isString = 'f', isUserFile = ' '; TPH isPH =phNo; //typedef enum TPH {phRE,phER,phNo}; char src[257],dst[257], dst1[15], dst2[15], sf1[15],sf2[15]; InitLibrary(); if (argc<2) { __re_cmdprint(); exit(0); } strncpy(src,__ru32libinfo,256); if (argv[1][0]=='-') isopt =1; if (argc>6+isopt) { if (strlen(argv[6+isopt])>2) { isUserFile = argv[6+isopt][1]; strncpy (userfile, (argv[6+isopt])+2, 80); } // else isUserFile = ' '; } if (argc>5+isopt) isString = (argv[5+isopt])[0]; if (isString != 's' && isString !='d') isString = 'f'; if (argc>4+isopt) strncpy(cpito, argv[4+isopt], 60); if (argc>3+isopt) strncpy(cpifrom, argv[3+isopt], 60); if (argc>2+isopt) strncpy(fnto, argv[2+isopt], 80); if (argc>1+isopt) { /*if (isString=='s') strncpy(src, argv[1+isopt], 256); else*/ strncpy(fnfrom,argv[1+isopt], 80); } if (isopt==1) { isVer = !(re4pos('n',argv[1])>-1); if(re4pos('E',argv[1])>-1) isPH=phRE; else if(re4pos('R',argv[1])>-1) isPH=phER; if(re4pos('N',argv[1])>-1) isPH=phNo; isExt = !(re4pos('s',argv[1])>-1); } // 11-Feb-2000 by DLL bool sameFile = false; if (!strcmp(fnfrom,fnto) && strlen(fnfrom)>0) { sameFile=true; strcat(fnto,".re-tmp"); } // End of changes __re_cmd (fnfrom, fnto, cpifrom, cpito, isString, isUserFile, userfile, isExt, isPH, isVer); // 11-Feb-2000 by DLL if (sameFile) { remove (fnfrom); rename (fnto,fnfrom); } remove ("_$tmpspc.tmp"); // End of changes } re-0.1.orig/src/ru32au.c0100644000000000001440000002443606762571052013704 0ustar rootusers/****** ru32au.c ******/ #include #include "ru32cp.h" #include "ru32var.h" int ffreq[256]; //i: 0-255 int freqblock[16]; int bestblock[4]; int __CpiFrom,__CpiTo; int uppeset,loweset,freqmax; //(-------------)// //char wrkstr_au [270]; /* temporary string buffers */ //(-------------)// extern int/*bool*/ TestText(void); extern int/*bool*/ isLatin(void); extern int/*bool*/ isOdd(void); extern int/*bool*/ nInBest(int iblock, int count); extern int/*bool*/ GetTestRes(char* m_res, int *CpimFrom, int * CpimTo); extern int/*bool*/ TestKoi8(void); extern int/*bool*/ TestLatin(void); extern float SampleMean (char* src); extern int SampleMin (char* src); extern int SampleMax (char* src); extern void SelectBestBlocks (int BaseBlock); // BaseBlock: 0 - 8 extern int SymbolDistribution (FILE *f1); extern void GetFreqs (int* tofreqs, int* tofreqblock, int *uppeset0, int *loweset0, int *freqmax0); extern void PutFreqs (int* fromfreqs, int* fromfreqblock, int uppeset0, int loweset0, int freqmax0); extern void SymbolDistribution_for_Try (int *ffreq0, int* freqblock0, char* CpiTry); //--------------------------- AUTODEC :---------------- // extern int/*bool*/ TestText(void) { int i, t =true; SelectBestBlocks (8); // printf("TestText:loweset=%i,uppeset=%i\n",loweset,uppeset); if (isLatin()) t =TestLatin(); else if (nInBest(8,4) && nInBest(9,4) && nInBest(10,4) && nInBest(11,4)) t =TestKoi8(); else if (nInBest(12,4) && nInBest(13,4) && nInBest(14,4) && nInBest(15,4)) { __CpiFrom = GetCPIbyName("F_Utf-part"); __CpiTo = WinCPI; } else if (nInBest(11,4) && nInBest(12,4) && nInBest(13,4) && nInBest(15,4)) { __CpiFrom = GetCPIbyName("Dos"); __CpiTo = WinCPI; } else if (nInBest(8,4) && nInBest(9,4) && nInBest(10,4) && nInBest(15,4)) { __CpiFrom = GetCPIbyName("Iso"); // __CpiTo = WinCPI; } else if ( nInBest(10,4) && nInBest(11,4) && nInBest(12,4) && ( nInBest(8,4) || nInBest(9,4) ) ) { __CpiFrom = GetCPIbyName("Mac"); __CpiTo = WinCPI; } else if ( isOdd () ) { __CpiFrom = OddCPI; __CpiTo = WinCPI; } else { __CpiFrom = 0; __CpiTo = 0; t = false; } //printf ("TestText:from=%i to=%i\n",__CpiFrom,__CpiTo); return t; }; extern int/*bool*/ nInBest(int iblock, int count) { int i, t =true; for (i=0; i< count; i++) if (iblock==bestblock[i]) t =false; // printf("nInBest %i %i = %c\n",iblock,count,t?'t':'f'); return t; } extern int/*bool*/ isOdd(void) { //printf("isOdd %c\n",( ffreq[freqmax]>uppeset/3 )?'t':'f'); return ( ffreq[freqmax]>uppeset/3 ); } extern int/*bool*/ isLatin(void) { //printf("isLatin %c\n",( loweset>5*uppeset )?'t':'f'); return ( loweset>5*uppeset ); } extern int/*bool*/ GetTestRes(char* m_res, int *CpimFrom, int *CpimTo) { m_res[0] = GetCodepageByNumber(__CpiFrom)[0]; if (__CpiTo == WinCPI) m_res[1] = '\0'; else { m_res[1] = tolowerANSI(GetCodepageByNumber(__CpiTo)[0]); m_res[2] = '\0'; } (*CpimFrom) = __CpiFrom; (*CpimTo) = __CpiTo; } extern int/*bool*/ TestKoi8(void) { float aKoi,aMKoi,aWin; int t =true; aKoi = SampleMean(""); aMKoi = SampleMean(""); aWin = SampleMean(""); //printf("aKoi=%f, aMKoi=%f, aWin=%f\n",aKoi,aMKoi,aWin); if (aKoi>aMKoi && aKoi>aWin) { __CpiFrom = GetCPIbyName("Koi"); __CpiTo = WinCPI; } else if (aMKoi>aWin) { __CpiFrom = WinCPI; __CpiTo = GetCPIbyName("Koi"); } else { __CpiFrom = 0; __CpiTo = 0; t =false; }; return t; }; extern int/*bool*/ TestLatin(void) { int imim64, imimuu, imimbin, iexpress, iall, i ; int t =true; iall = 0; for (i = 0; i< 256; i++) iall += ffreq[i]; imim64 = 0; for (i = 0; i< 64; i++) imim64 +=ffreq[mim64[i]]; imimuu = 0; for (i = 0; i< 64; i++) imimuu +=ffreq[mimuu[i]]; imimbin =0; for (i = 0; i< 64; i++) imimbin +=ffreq[mimbin[i]]; iexpress = ffreq['&']+ffreq['#']+ffreq[';']; //printf("TestLatin: iall=%i imimuu=%i imimbin=%i iexpress=%i\n", // iall, imimuu, imimbin, iexpress); if (ffreq['='] >iall/5) { __CpiFrom = HexCPI; __CpiTo = WinCPI; } else if (ffreq['%'] >iall/5) { __CpiFrom = GetCPIbyName("%Hex"); __CpiTo = WinCPI; } else if (ffreq['\\']+ffreq[39]+ffreq['{']+ffreq['}'] >iall/5) { __CpiFrom = GetCPIbyName("\\Hex"); __CpiTo = WinCPI; } else if ( imim64 > (iall-imim64) *5 ) { if (ffreq['-'] >ffreq['/']) __CpiFrom = XxCPI; else __CpiFrom = MimeCPI; __CpiTo = WinCPI; } else if ( iexpress >iall/4 && (ffreq['#']*2)>SampleMean("&;") ) { __CpiFrom = ExpressCPI; __CpiTo = WinCPI; } else if ( SampleMin("&;") > SampleMean("0123456789")*5 ) { __CpiFrom = HtmCPI; __CpiTo = WinCPI; } else if ( imimuu > (iall-imimuu)*4 ) { __CpiFrom = UuCPI; __CpiTo = WinCPI; } else if ( imimbin > (iall-imimbin)*4 ) { __CpiFrom = BinhexCPI; __CpiTo = WinCPI; } else if ( SampleMean("`hqb") > SampleMean("~}zt")*3 ) { __CpiFrom = GetCPIbyName("AFF"); __CpiTo = WinCPI; } else if ( SampleMean("AO") > 2*SampleMean("QWF") ) { __CpiFrom = PolCPI; __CpiTo = WinCPI; } else if ( SampleMean("[FJ") > 3*SampleMean("]A") ) { __CpiFrom = GetCPIbyName("Shift"); __CpiTo = WinCPI; } else { __CpiFrom = 0; __CpiTo = 0; t =false; }; return t; }; extern float SampleMean (char* src) { int i,n,cc; float s; n = strlen(src); if (n<1) return 0.0; s = 0.0; for (i = 0; i< n; i++) { cc = (src[i]+0x100) % 0x100; s += ( ffreq[(tolowerANSI(cc)+0x100) %0x100] +ffreq[(toupperANSI(cc)+0x100) %0x100] ); } return (s/n); }; extern int SampleMin (char* src) { int i,n,s,fr,cc; n = strlen(src); if (n<1) return 0; s = uppeset+loweset+10; for (i = 0; i< n; i++) { cc = (src[i]+0x100) % 0x100; fr = ( ffreq[(tolowerANSI(cc)+0x100) %0x100] +ffreq[(toupperANSI(cc)+0x100) %0x100] ); if (s > fr) s = fr; //printf("cc=%i adr1=%i adr2=%i fr %i\n",cc,(tolowerANSI(cc)+0x100) %0x100, // (toupperANSI(cc)+0x100) %0x100, fr ); } //printf ("SampleMin:res=%i\n",s); return s; }; extern int SampleMax (char* src) { int i,n,s,fr,cc; n = strlen(src); if (n<1) return 0; s = 0; for (i = 0; i< n; i++) { cc = (src[i]+0x100) % 0x100; fr = ( ffreq[(tolowerANSI(cc)+0x100) %0x100] +ffreq[(toupperANSI(cc)+0x100) %0x100] ); if (s < fr) s = fr; } //printf ("SampleMax:res=%i\n",s); return s; }; extern void SelectBestBlocks (int BaseBlock) // BaseBlock: 0 - 8 { int i, m, k; int bb [16]; // printf("SelectBest freqbl 8: %i\n",freqblock[8]); for (i=0; i <16; i++) bb[i] = freqblock[i]; for (i=0; i< 4; i++) { m = 0; for (k=BaseBlock; k< 16; k++) // { printf("k=%i m=%i bbk=%i bbm=%i\n",k,m,bb[k],bb[m]); if (bb[k]>bb[m]) m = k; // } bestblock[i] = m; bb[m] = 0; }; //printf ("SelectBest: %i %i %i %i\n", bestblock[0], bestblock[1], bestblock[2], bestblock[3]); }; extern int/*bool*/ SymbolDistribution ( FILE *f1) // returns true if tmp-file of first 500 chars is created { int ch, cc, i, i_b; int/*bool*/ istmp; FILE *ftmp; istmp = ( (ftmp=fopen("_$tmpspc.tmp","wb")) != NULL ); // printf("SymbolDistr: istmp=%c\n",(istmp)?'t':'f'); if (istmp) { cc = 0; fseek (f1, 0L, SEEK_SET); while ( (ch=getc(f1)) != EOF && cc++ < 500 ) fputc(ch, ftmp); /*if (ftmp !=NULL)*/ fclose (ftmp); } fseek (f1, 0L, SEEK_SET); for (i=0; i< 256; i++) ffreq[i] = 0; for (i=0; i< 16; i++) freqblock[i] = 0; uppeset = 0; loweset = 0; while ( (ch=getc(f1)) != EOF ) { cc = ch; // otl: if(cc<0) cc+=256; ffreq[cc] +=1; //printf ("f1:cc=%i ",cc); if (cc >= 0x10) { i_b = (cc / 16); freqblock[i_b] +=1; if (cc>=0x80) uppeset++; else if (cc>=0x20) loweset++; } } freqmax = 0; for (i=128; i< 256; i++) if (ffreq[i] > ffreq[freqmax]) freqmax=i; //printf("SymbDistr: uppeset=%i,loweset=%i,freqmax=%i\nfreqbl0,8-15=%i %i %i %i %i %i %i %i %i :\n ", // uppeset, loweset, freqmax, // freqblock[0], freqblock[8], freqblock[9], freqblock[10], freqblock[11], // freqblock[12], freqblock[13], freqblock[14], freqblock[15]); return istmp; }; extern void GetFreqs (int* toffreq, int* tofreqblock, int *uppeset0, int *loweset0, int *freqmax0) { int i; for (i=0; i< 256; i++) *(toffreq+i) = ffreq[i]; for (i=0; i< 16; i++) *(tofreqblock) = freqblock[i]; *uppeset0 = uppeset; *loweset0 = loweset; *freqmax0 = freqmax; } extern void PutFreqs (int* fromffreq, int* fromfreqblock, int uppeset0, int loweset0, int freqmax0) { int i; for (i=0; i< 256; i++) ffreq[i] = *(fromffreq+i); for (i=0; i< 16; i++) freqblock[i] = *(fromfreqblock+i); uppeset = uppeset0; loweset = loweset0; freqmax = freqmax0; }; extern void SymbolDistribution_for_Try (int *ffreq0, int* freqblock0, char* CpiTry) { int i, i_count, i_b; int cc; for (i=0; i< 256; i++) ffreq[i]=0; for (i=0; i< 16; i++) freqblock[i]=0; uppeset =0; loweset =0; for (i=0; i< 256; i++) { i_count = ffreq0[i]; // number of symbol i in source file cc = CpiTry[i]; // cc -to what is symbol i transferred after macros if (cc<0) cc +=256; ffreq[cc] += i_count; // printf ("%i-> %i(%i) \n",i,cc,i_count); if ( cc>=0x10 ) { i_b = (cc / 16); freqblock[i_b] += i_count; if ( cc>= 0x80 ) uppeset += i_count; else if ( cc>= 0x20 ) loweset += i_count; }; }; freqmax = 0; for (i=128; i< 256; i++) if (ffreq[i]>ffreq[freqmax]) freqmax =i; //printf("SymbDistr_forTry: uppeset=%i,loweset=%i,freqmax=%i\nfreqbl 0,8-15=%i %i %i %i %i %i %i %i %i :\n ", // uppeset, loweset, freqmax, // freqblock[0], freqblock[8], freqblock[9], freqblock[10], freqblock[11], // freqblock[12], freqblock[13], freqblock[14], freqblock[15]); }; re-0.1.orig/src/ru32au.h0100644000000000001440000000216006760317210013667 0ustar rootusers/****** ru32au.h ******/ #ifndef __RU32AU_DEF #define __RU32AU_DEF 1 //#include "ru32cp.h" //#include "ru32var.h" // int ffreq[256]; //i: 0-255 // int freqblock[16]; // int bestblock[4]; // int __CpiFrom,__CpiTo; // int uppeset,loweset,freqmax; extern int/*bool*/ TestText(void); extern int/*bool*/ isLatin(void); extern int/*bool*/ isOdd(void); extern int/*bool*/ nInBest(int iblock, int count); extern int/*bool*/ GetTestRes(char* m_res, int *CpimFrom, int *CpimTo); extern int/*bool*/ TestKoi8(void); extern int/*bool*/ TestLatin(void); extern float SampleMean (char* src); extern int SampleMin (char* src); extern int SampleMax (char* src); extern void SelectBestBlocks (int BaseBlock); // BaseBlock: 0 - 8 extern int SymbolDistribution (FILE *f1); extern void GetFreqs (int* toffreq, int* tofreqblock, int *uppeset0, int *loweset0, int *freqmax0); extern void PutFreqs (int* fromffreq, int* fromfreqblock, int uppeset0, int loweset0, int freqmax0); extern void SymbolDistribution_for_Try (int *ffreq0, int* freqblock0, char* CpiTry); #endif re-0.1.orig/src/ru32call.c0100644000000000001440000001431407050305070014166 0ustar rootusers /***** ru32call.c *****/ #include #include #include #include "ru32un.h" #include "ru32cp.h" #include "ru32var.h" #include "ru32mau.h" extern void __re_cmdprint(void); extern void UserProcessFile(char* fnfrom, char*fnto, char*cpifrom, char* cpito); extern void UserProcessString(char* fnfrom, char*fnto, char*cpifrom, char* cpito); extern void __re_cmd (char* fnfrom, char* fnto, char* cpifrom, char* cpito, char isString, char isUserFile, char* userfile, int/*bool*/ isExt, TPH isPH, int/*bool*/ isVer); // usage: // re_cmd [opts] // opts: -[v|n][E|R|N][e|s]\n", // : s or d(dbf) or f, default-f> // : -u,-l,-s : // load user cpi, load new addcpi list, save addcpi list. extern void __re_cmdprint(void) { char dst[81], dst1[15], dst2[15], sf1[15],sf2[15]; int i,j,ncp,ncp1,ncp2; printf("\n%s\n\n",__ru32libinfo); printf(" usage:\n %s\n\n", "re options "); printf("\n %s %s %s %s %s %s %s %s", "options: [-v][-E|-R|-N][-e|-s]\n", " -v - tells what is processing\n", " -n - don't tells what is processing (default) \n", " -E - converts all p,H from Russian to English\n", " -R - converts all p,H from English to Russian\n", " -N - lets all p,H Russian or English as in text (default)\n", " -e - converts all symbols 0x80 - 0xFF\n", " -s - converts only 64 symbols of Russian Alphabet (default)\n\n" ); printf(", - any from list (default - W,K):\n"); ncp=GetCodepagesMaxCount(); ncp1 = ncp/2; ncp2=ncp%2; for (i=0; i= 0 ) j += 4; strncat (dst1," ", 12-j); if (i=",'?',"try autoconvert\n\n"); printf("%s%s%s","For , only first symbol significant,", " case sensitive;\n", " autoconvert option disabled for =s or d.\n\n\n" ); printf ("decrypt or encrypt file-from into file-to:\n"); printf(" cpi-from or cpi-to = \"!\",\n"); printf(" using arbitrary string in other cpi as passwd.\n\n\n"); printf("%s %s %s %s %s", ": s(string) or d(dbf) or f(file), default-f : \n", " if file - convert text-file filename-from -> filename-to\n", " if dbf - convert all text fields in DBFfile filename-from -> filename-to\n", " if string - convert string and print result to screen\n", " (if string -- arg value not significant).\n\n\n" ); printf("%s %s %s %s", ": -u or -l or -s or none, default-none :\n", " if -u - load user cpi from file \n", " if -l - load new addcpi set from file \n", " if -s - save current addcpi set as file .\n\n\n" ); } extern void UserProcessString(char* fnfrom, char*fnto, char*cpifrom, char* cpito) { if (strcmp(cpito,"--m")==0) MacroProcess (fnfrom, fnto, cpifrom, 's'); else ProcessString (fnfrom, fnto); } extern void UserProcessFile(char* fnfrom, char*fnto, char*cpifrom, char* cpito) { //printf ("call cpito=(==,!=--m)\"%s\" (%i,%i)", cpito,strcmp(cpito,"--m"),strcmp(cpito,"-m")); if (cpifrom[0]=='?') { SetAuto2Cpi (GetCPIbyName(cpito)); AutoProcessFile (fnfrom, fnto); } else if (strcmp(cpito,"--m")==0) MacroProcess (fnfrom, fnto, cpifrom, 'f'); else ProcessFile (fnfrom, fnto); } extern void __re_cmd (char* fnfrom, char* fnto, char* cpifrom, char* cpito, char isString, char isUserFile, char* userfile, int/*bool*/ isExt, TPH isPH, int/*bool*/ isVer) { int cp1=-1,cp2=-1,resUnicode; char sf1[15]; SetisExtended (isExt); SetVerbose (isVer); SetPh (isPH); cp1=GetCPIbyName(cpifrom); cp2=GetCPIbyName(cpito); SetCp1(cp1); SetCp2(cp2); if (isUserFile=='u') { LoadUserAlphFile(userfile); if(isVer) printf ("**** Load User Cpi from <%s>\n", userfile); } else if (isUserFile=='l') { LoadAddCPI(userfile); if(isVer) printf ("**** Load Additional Cpi set from <%s>\n", userfile); } else if (isUserFile=='s') { SaveAddCPI(userfile); if(isVer) printf ("**** Save Additional Cpi set as <%s>\n", userfile); } // /*otl printf("isUserFile **%c**\n",isUserFile); if (cpito[0]=='!') { EncryptFile(fnfrom,fnto,cpifrom); if(isVer) printf ("\n**** encrypt %s -> %s\n",fnfrom,fnto); } else if (cpifrom[0]=='!') { DecryptFile(fnfrom,fnto,cpito); if(isVer) printf ("\n**** decrypt %s -> %s\n",fnfrom,fnto); } else if (isString=='s') { // strcpy (src, fnfrom); UserProcessString(fnfrom,fnto,cpifrom,cpito); // src,dst if(isVer) printf ("\n**** string %s (%s:%i) -> %s (%s:%i)\n",fnfrom,cpifrom,cp1, fnto,cpito,cp2); // ..src,cpifrom,cp1,dst,cpto,cp2 } else if (isString=='d') { SetDBF (true); ProcessFile(fnfrom,fnto); if(isVer) printf ("\n**** dbf %s (%s:%i) -> %s (%s:%i)\n",fnfrom,cpifrom,cp1, fnto,cpito,cp2); } else { if (cpifrom[0]=='?') printf("Trying autoconvert..\n"); resUnicode = CheckUnicodeFile(fnfrom,"__tempre.txt"); if (resUnicode == 0) UserProcessFile(fnfrom,fnto,cpifrom,cpito); else if (resUnicode == 1) { UserProcessFile("__tempre.txt",fnto,cpifrom,cpito); remove ("__tempre.txt"); } if (cpifrom[0]=='?') strcpy (cpifrom, GetSelMac()); cp1=GetCp1(); cp2=GetCp2(); if(isVer) printf ("\n**** %s (%s%s:%i) -> %s (%s:%i)\n", fnfrom,(resUnicode == 1)?"Unicode+":"",cpifrom,cp1, fnto,cpito,cp2); } } re-0.1.orig/src/ru32call.h0100644000000000001440000000123706764040676014216 0ustar rootusers /***** ru32call.h *****/ extern void __re_cmdprint(void); extern void UserProcessFile(char* fnfrom, char*fnto, char*cpifrom, char* cpito); extern void UserProcessString(char* fnfrom, char*fnto, char*cpifrom, char* cpito); extern void __re_cmd (char* fnfrom, char* fnto, char* cpifrom, char* cpito, char isString, char isUserFile, char* userfile, int/*bool*/ isExt, TPH isPH, int/*bool*/ isVer); // re_cmd [opts] // opts: -[v|n][E|R|N][e|s]\n", // : s or d(dbf) or f, default-f> // : -u,-l,-s : // load user cpi, load new addcpi list, save addcpi list. re-0.1.orig/src/ru32cp.c0100644000000000001440000003256206762046156013702 0ustar rootusers/****** ru32cp.c ******/ #include #include #include typedef char Tcpi[4][65]; //--------------------------- CONSTNTS :---------------- // #define POINTS64 "................................................................" Tcpi CPI[32] = { {"Windows","", POINTS64,POINTS64}, {"Dos","", POINTS64,POINTS64}, {"KOI-8","", POINTS64,POINTS64}, {"Latin","ABVGDEGZIJKLMNOPRSTUFHCCSS^Y^EUAabvgdegzijklmnoprstufhccss^y^eua", POINTS64,POINTS64}, {"Iso","", POINTS64,POINTS64}, {"HEX","","",""}, {"ShiftKbrd","FZf,dult;pbqrkvyjghcnea[wxio]sm\".z", POINTS64,POINTS64}, {"Mac","", POINTS64,POINTS64}, {"AFF","@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", POINTS64,POINTS64}, {"Odd(UTF8_1)","","",""}, {"Base64","","",""}, {"Express","","",""}, {"T-Html","","",""}, {"User","", POINTS64,POINTS64}, {"-uue","","",""}, {"_xxe","","",""}, {"%hex","","",""}, {"\\'hex","","",""}, {"Graph_win","", POINTS64,POINTS64}, {"","","",""}, {"+UTF7-","","",""}, {"C_MIC","", POINTS64,POINTS64}, {"Y_c16","", POINTS64,POINTS64}, {"Z_c32","", POINTS64,POINTS64}, {"F(UTF8_2)","", POINTS64,POINTS64}, {"Pict","ABDEKMHOPCTYXaekopcyx", POINTS64,POINTS64}, {"N_Estl","ABEKMHOPCTXa떗eopcx", POINTS64,POINTS64}, {"V_Vpp855","쭧諶ࠢ묦窵", POINTS64,POINTS64}, {"X_sp","???????????ݰ?߮?", POINTS64,POINTS64}, {"J_diff","", POINTS64,POINTS64}, {"Q","", POINTS64,POINTS64}, {"R","", POINTS64,POINTS64} }; /* -8 -9 -a -b -c -d -e -f */ char uni_dead [128] = {0x02,0x04,0x03,0x04,0x1A,0x20,0x53,0x04,0x1E,0x20,0x26,0x20,0x20,0x20,0x21,0x20 ,0x88,0x00,0x30,0x20,0x09,0x04,0x39,0x20,0x0A,0x04,0x0C,0x04,0x0B,0x04,0x0F,0x04 ,0x52,0x04,0x18,0x20,0x19,0x20,0x1C,0x20,0x1D,0x20,0x22,0x20,0x13,0x20,0x14,0x20 ,0x98,0x00,0x22,0x21,0x59,0x04,0x3A,0x20,0x5A,0x04,0x5C,0x04,0x5B,0x04,0x5F,0x04 ,0xA0,0x00,0x0E,0x04,0x5E,0x04,0x08,0x04,0xA4,0x00,0x90,0x04,0xA6,0x00,0xA7,0x00 ,0x01,0x04,0xA9,0x00,0x04,0x04,0xAB,0x00,0xAC,0x00,0xAD,0x00,0xAE,0x00,0x07,0x04 ,0xB0,0x00,0xB1,0x00,0x06,0x04,0x56,0x04,0x91,0x04,0xB5,0x00,0xB6,0x00,0xB7,0x00 ,0x51,0x04,0x16,0x21,0x54,0x04,0xBB,0x00,0x58,0x04,0x05,0x04,0x55,0x04,0x57,0x04 }; char CPILetter[33]=""; int CPIcount, CPI_ADDcount ; char *mim ; char hexsmb ; int WinCPI,PolCPI,HexCPI,OddCPI,MimeCPI,ExpressCPI,UserCPI,HtmCPI,XxCPI,UuCPI, BinhexCPI,Utf7CPI; int CPImax = 32; int CPI_STANDcount = 14; int CPIadd_defcount = 15; int CPIaddNoChange = 7; // uue,xxe,%hex,\hex,graph_win,,UTF7,C,X,Y,F char macrodivlet = '~'; int CPIname = 0; int CPIbody = 1; int CPIBodyWin = 2; int CPIBodyDos = 3; int ExtCPIwin = 64; int ExtCPIdos = 64; // 48-pseudographics // + DOS #251#254 - "square root" and "black square - end of chapter" // + KOI #147#151#152#153#155#157#159 // - upper half of integral,nearly equal,less or equal,great or equal, // lower half of integral,in power z,integer dividing // + 7 reserv // ExtCpiAutoLength=2; int pLocation = 48; int HLocation = 13; char *dubl_auto = "HOBE-_\\%?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"; char *mimxx ="+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; char * mimbin="!\"#$%&'()*+,-012345689@ABCDEFGHIJKLMNPQRSTUVXYZ[`abcdefhijklmpqr"; // in mimuu - quote: chr($27) ; extern int re4pos(char ccwhat, char *sswhere); extern int GetCPIbyName (char *myPage); extern void InitCPIconst (void); extern void InitCPIdefines (void); extern void InitCPIExtended (void); extern /*Boolean*/ int no2this(int Cp2); extern int GetCodepagesCount(void); extern int GetCodepagesMaxCount(void); //extern int GetWinCPI(void); //extern int GetUserCPI(void); extern const char* GetCodepageByNumber (int pnum); extern const char* GetDublAuto(void); //-----------------------// extern int re4pos (char ccwhat, char *sswhere) { char *ss; // int i; // for (i=0,ss=sswhere; (*ss!='\0')&&(*ss!=ccwhat); ss++,i++); // if (*ss!=ccwhat) i=-1; ss = strchr (sswhere, ccwhat); return (ss != NULL) ? ss-sswhere : -1 ; } extern int GetCPIbyName (char *myPage) { char cc; cc = (char)(toupper((int)myPage[0])); // /*otl:*/ printf ("myP=%s cc=%c CPILet=%s\n",myPage,cc,CPILetter); return re4pos(cc, CPILetter); }; extern int /*Boolean*/ no2this(int Cp2) { return ( re4pos(CPILetter[Cp2],no2cpi)>-1 ); }; extern void InitCPIconst(void) { int i,c; mim = mim64; hexsmb = '='; CPI_ADDcount = CPIadd_defcount; CPIcount = CPI_STANDcount; c = CPI_STANDcount+CPI_ADDcount; for (i=0; i < c; i++) { CPILetter[i]=(char)toupper((CPI[i][CPIname])[0]); } CPILetter[c] = '\0'; // /*otl:*/ printf("c=%i CPILetter=%s\n",c,CPILetter); InitCPIExtended(); InitCPIdefines(); }; extern void InitCPIdefines(void) { WinCPI = GetCPIbyName("Win"); //1; PolCPI = GetCPIbyName("Lat"); //4; HexCPI = GetCPIbyName("Hex"); //6; OddCPI = GetCPIbyName("Odd"); //10; MimeCPI = GetCPIbyName("Base64"); //11; ExpressCPI = GetCPIbyName("Express"); //12; UserCPI = GetCPIbyName("User"); //14; HtmCPI = GetCPIbyName("T-Html"); //; XxCPI = GetCPIbyName("_Xxe"); //; UuCPI = GetCPIbyName("-Uue"); //; BinhexCPI = GetCPIbyName(""); //; Utf7CPI = GetCPIbyName("+UTF7-"); //; }; extern void InitCPIExtended() { int i,c; char *is,*cs; //old: yo YO (2 byte) + '<<','>>' (2 byte) + pseudographics (48 byte): c = GetCPIbyName("WIN"); strcpy ( CPI[c][2], // ''; // =A8=B8=AB=BB, i.e. #168#184#171#187 "" ); c = GetCPIbyName("Gr_win"); strcpy ( CPI[c][2], // '<>'; "<>" ); strcpy ( CPI[c][3], "...|-=--==|==-=------+=-======+=-=--==--=--....................." ); c = GetCPIbyName("DOS"); strcpy ( CPI[c][2], ".....................\xf9.........." ); strcat ( CPI[c][2], "\xff\xf6\xf7.\xfd...\xf0.\xf2....\xf4\xf8......\xfa\xf1\xfc\xf3....\xf5" ); // '<>'; // =F0=F1 i.e. #240#241 // '.....................'#249'..........'+ // #255#246#247'.'#253'...'#240'.'#242'....'#244#248'......'#250#241#252#243'....'#245; strcpy (CPI[c][3], "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf" ); strcat (CPI[c][3], "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf" ); strcat (CPI[c][3], "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf" ); strcat (CPI[c][3], "\xfb\xfe.............." ); // #176#177#178#179#180#181#182#183#184#185#186#187#188#189#190#191+ // #192#193#194#195#196#197#198#199#200#201#202#203#204#205#206#207+ // #208#209#210#211#212#213#214#215#216#217#218#219#220#221#222#223+ // #251#254'..............'; c = GetCPIbyName("KOI"); strcpy (CPI[c][2], ".....................\x95.........." ); strcat (CPI[c][2], "\x9a.......\xb3\xbe......\x9c......\x9e\xa3......." ); // {'................................'; // - according to the book } // ''; // {#176#177#178#179#180#181#182#183#184#185#186#187#188#189#190#191+ // #128#129#130#131#132#133#134#135#136#137#138#139#140#141#142#143+ // #144#145#146#147#148#149#150#151#152#153#154#155#156#157#158#159; // - according to the book } strcpy (CPI[c][3], "\x90\x91\x92\x81\x87\xb2\xb4\xa7\xa6\xb5\xa1\xa8\xae\xad\xac\x83" ); strcat (CPI[c][3], "\x84\x89\x88\x86\x80\x8a\xaf\xb0\xdb\xa5\xbb\xb8\xb1\xa0\xbe\xb9" ); strcat (CPI[c][3], "\xba\xb6\xb7\xaa\xa9\xa2\xa4\xbd\xbc\x85\x82\x8d\x8c\x8e\x8f\x8b" ); strcat (CPI[c][3], "\x96\x94\x93\x97\x98\x99\x9b\x9d\x9f......." ); // #144#145#146#129#135#178#180#167#166#181#161#168#174#173#172#131+ // #132#137#136#134#128#138#175#176#219#165#187#184#177#160#190#185+ // #186#182#183#170#169#162#164#189#188#133#130#141#140#142#143#139+ // #150#148#147#151#152#153#155#157#159'.......'; c = GetCPIbyName("LAT"); strcpy (CPI[c][2], "........................................E...............e......." ); c = GetCPIbyName("ISO"); strcpy (CPI[c][2], "\xa2\xa3.\xf3........\xaa\xac\xab\xaf\xf2.....\xf3...\xf9.\xfa\xfc\xfb\xff" ); strcat (CPI[c][2], "\xa0\xae\xfe\xa8...\xfd\xa1.\xa4....\xa7..\xa6\xf6....\xf1\xf0\xf4.\xf8\xa5\xf5\xf7" ); // '<>'; //=A1=F1, i.e. #161#241 // #162#163'.'#243'........'#170#172#171#175#242'.....'#173'...'#249'.'#250#252#251#255+ // #160#174#254#168'...'#253#161'.'#164'....'#167'..'#166#246'....'#241#240#244'.'#248#165#245#247; // { '.....................'#250'...'#249'......'+ - according to the book // '.'#247#248'.'#254'...'#161'.'#242'....'#245'.......'#251#241#253#243'....'#246; } // CPI[c,3]:= // { #155#156#157#165#167#131#132#133#134#151#149#145#146#139#140#160+ // #163#168#166#169#164#170#141#142#147#144#152#150#153#148#154#128+ // #129#130#135#136#137#138#143#158#159#162#160#171#172#173#174#175; - according to the book //} c = GetCPIbyName("Shift"); strcpy (CPI[c][2], "........................................~...............`......." ); // '~`'; c = GetCPIbyName("MAC"); strcpy (CPI[c][2], "\xab\xae.\xaf\xd7\xc9\xa0...\xbc.\xbe\xcd\xcb\xda" ); strcat (CPI[c][2], "\xac\xd4\xd5\xd2\xd3\xa5\xd0\xd1.\xaa\xbd.\xbf\xce\xcc\xdb" ); strcat (CPI[c][2], "\xca\xd8\xd9\xb7\xcd..\xa4\xdd\xa9\xb8\xc7\xc2.\xa8\xba" ); strcat (CPI[c][2], "\xa1\xb1\xa7\xb4..\xa6.\xde\xdc\xb9\xc8\xc0\xc1\xcf\xbb" ); // #171#174'.'#175#215#201#160'...'#188'.'#190#205#203#218+ // #172#212#213#210#211#165#208#209'.'#170#189'.'#191#206#204#219+ // #202#216#217#183#255'..'#164#221#169#184#199#194'.'#168#186+ // #161#177#167#180'..'#166'.'#222#220#185#200#192#193#207#187; // ''; //=DD=DE=C7=C8 i.e. #221#222 #199#200 strcpy (CPI[c][3], "................................................" ); strcat (CPI[c][3], "\xc3...\xb2\xb3..\xd6......." ); // #195'...'#178#179'..'#214'.......'; c = GetCPIbyName("AFF"); strcpy (CPI[c][2], "........................................(...............8......." ); // '(8'; c = GetCPIbyName("Pict"); strcpy (CPI[c][2], "........................................E...............e......." ); //'Ee'; c = GetCPIbyName("User"); //{MIC} strcpy (CPI[c][2], ".....................\xf9.........." ); strcat (CPI[c][2], "\xff......\xd6........\xf8\xf1...\xe6.\xfa.\xd5......" ); strcpy (CPI[c][3], "\xd0\xd1\xd2\xd3\xd4....\xc6\xc7\xd7\xd8..\xcf" ); strcat (CPI[c][3], "\xc0\xc1\xc2\xc3\xc4\xc5..\xc8\xc9\xca\xcb\xcc\xcd\xce." ); strcat (CPI[c][3], ".........\xd9\xda\xdb\xdc\xdd\xde\xdf" ); strcat (CPI[c][3], "\xfb\xfe\xf4\xf7\xf3\xf2\xf5\xfd\xf6......." ); //pseudographics - is exactly as in the book // #208#209#210#211#212'....'#198#199#215#216'..'#207+ // #192#193#194#195#196#197'..'#200#201#202#203#204#205#206'.'+ // '.........'#217#218#219#220#221#222#223+ // #251#254#244#247#243#242#245#253#246'.......'; // maybe better to turn off, for not to disturbe macros processing ? ///*otl:*/ for (i=0; i<32; i++) printf("CP[%i][0]=%s\n",i,CPI[i][0]); c = GetCPIbyName("C_MIC"); i = GetCPIbyName("User"); ///*otl*/printf("C %i,U %i\n",c,i); //cs=CPI[0][0]; is=CPI[i][2]; ///*otl:*/ printf("cs=%s\n is=%s\n",cs,is); // strcpy (cs, "--"/*is*/); strcpy (CPI[c][2], CPI[i][2] ); strcpy (CPI[c][3], CPI[i][3] ); }; extern int GetCodepagesCount(void) { return CPIcount; } extern int GetCodepagesMaxCount(void) {return CPI_STANDcount+CPIadd_defcount;} //extern int GetWinCPI(void) { return WinCPI; }; //extern int GetUserCPI(void) { return UserCPI; }; extern const char* GetCodepageByNumber (int pnum) { if (pnum<0 || pnum> CPI_STANDcount+CPI_ADDcount) return "??"; else return CPI[pnum][CPIname]; }; extern const char* GetDublAuto(void) { return dubl_auto; }; re-0.1.orig/src/ru32cp.h0100644000000000001440000000264106760317210013670 0ustar rootusers/****** ru32cp.h ******/ #ifndef __RU32CP_DEF #define __RU32CP_DEF 1 #include #include typedef char Tcpi[4][65]; extern Tcpi CPI[]; extern char uni_dead []; extern char CPILetter[]; extern int CPIcount, CPI_ADDcount ; extern char *mim ; extern char hexsmb ; extern int WinCPI,PolCPI,HexCPI,OddCPI,MimeCPI,ExpressCPI,UserCPI,HtmCPI,XxCPI,UuCPI, BinhexCPI,Utf7CPI; extern int CPImax; extern int CPI_STANDcount; extern int CPIadd_defcount; extern int CPIaddNoChange; // uue,xxe,%hex,\hex,graph_win,,UTF7,C,X,Y,F extern char macrodivlet; extern int CPIname; extern int CPIbody; extern int CPIBodyWin; extern int CPIBodyDos; extern int ExtCPIwin; extern int ExtCPIdos; extern int pLocation; extern int HLocation; extern char *dubl_auto; extern char *no2cpi; extern char *mim64; extern char *mimuu; extern char *mimxx; extern char *mimbin; extern int re4pos(char ccwhat, char *sswhere); extern int GetCPIbyName (char *myPage); extern void InitCPIconst (void); extern void InitCPIdefines (void); extern void InitCPIExtended (void); extern /*Boolean*/ int no2this(int Cp2); extern int GetCodepagesCount(void); extern int GetCodepagesMaxCount(void); //extern int GetWinCPI(void); //extern int GetUserCPI(void); extern const char* GetCodepageByNumber (int pnum); extern const char* GetDublAuto(void); #endif re-0.1.orig/src/ru32fi.c0100644000000000001440000003563106762046156013676 0ustar rootusers/***** ru32fi.c *****/ #include #include #include #include "ru32cp.h" #include "ru32var.h" #include "ru32lat.h" extern char* Hex2Win (char* src, char* dst); extern char* Win2Hex (char* src, char *dst); extern void ConvertHEX (FILE* f1, FILE* f2); extern void ConvertToHEX (FILE* f1, FILE* f2); extern void TakeOddsFromFile (FILE* f1, FILE* f2); extern void DoMime64 (FILE* f1, FILE* f2); extern void DoBinHex (FILE* f1, FILE* f2); extern void DoExpress (FILE* f1, FILE* f2); extern char* TakeOddsFromString (char* src, char* dst); extern char* StringDoMime64 (char* src, char* dst); extern char* StringBinHex(char* src, char* dst); extern char* StringUtf7(char* src, char* dst); extern char* StringExpress (char* src, char* dst); extern char* DeleteTag (char* src, char* dst); //(-------------)// char wrkstr_fi [270], wrkstr_fi2[270]; /* temporary string buffers */ //(-------------)// extern void ConvertHEX (FILE* f1, FILE* f2) { char w,d,n1,n2,n0,w1,ordhex; int ch; ordhex = hexsmb; n1 = 99; n2 = 99; // don't wait for code pair n0 = 0; // no 'still waiting' ,i.e. 'have read n0=0 additional start symbols' while ( (ch=getc(f1)) != EOF ) { w = (char)ch; if (w==10 || w==13) goto WRT; if (n2==99) //if not waiting for code pair { if (w==ordhex) { n1 = 88; n2 = 88; n0 = 0; continue; } // start waiting for code pair else goto WRT; } if (n2==88 && hexsmb=='\\' && n0==0 && w==39) //chr(39) { //still waiting, have read n0=1 additional start symbol n0 = 1; continue; } if (n2==88) //if waiting for code pair { if ( (hexsmb!='\\' || (hexsmb=='\\' && n0==1)) && (w>=0x41 && w<=0x46) || (w>=0x61 && w<=0x66) || (w>=0x30 && w<=0x39)) { if ((w>=0x41 && w<=0x46)) d = 10+w-0x41; else if ((w>=0x61 && w<=0x66)) d = 10+w-0x61; else d = w-0x30; if (n1==88) // if wait for first code from pair { n1 = d; w1 = w; continue; } else // if wait for 2nd code from pair { n2 = d; w = n1*16 +n2; n1 = 99; n2 = 99; //skip waiting for code pair goto WRT; } } else // it turned out to be not a code pair ! { if (hexsmb!='\\') { d = ordhex; putc(d,f2); // we return '=' if (n1<88) putc(w1,f2); // and the first code if any }; if (w==ordhex) { n1 = 88; n2 = 88; n0 = 0; continue; } // start waiting for new code pair else if (hexsmb=='\\') continue; else { n1 = 99; n2 = 99; goto WRT; } } } WRT: putc(w,f2); } if (n2==88) // if file finished when we wait for code pair { d = ordhex; putc(d,f2); // we return '=' if (hexsmb=='\\') { d = 39; putc(d,f2); } // chr(#39) if (n1<88) putc(w1,f2); // and the first code if any } fflush(f2); }; extern char* Hex2Win (char* src, char* dst) { char *m1,*m2; char w,d,n1,n2,n0,w1,ordhex; int j, lensrc, ads; ordhex = hexsmb; ads = 0; m1 = src; m2 = dst; strcpy(dst, ""); n1 = 99; n2 = 99; // don't wait for code pair n0 = 0; // no 'still waiting' ,i.e. 'have read n0=0 additional start symbols' w1 = 13; // for no use, only to calm delphi on "may not be initialized" ;) lensrc = strlen(m1); for (j = 0; j < lensrc; j++) { w = m1[j]; if (w==10 || w==13) goto WRT; if (n2==99) //if not waiting for code pair { if (w==ordhex) { n1 = 88; n2 = 88; n0 = 0; continue; } // start waiting for code pair else goto WRT; } if (n2==88 && hexsmb=='\\' && n0==0 && w==39) // chr(39) { //still waiting, have read n0=1 additional start symbol n0 = 1; continue; } if (n2==88) //if waiting for code pair { if ( (hexsmb!='\\' || (hexsmb=='\\' && n0==1)) && (w>=0x41 && w<=0x46) || (w>=0x61 && w<=0x66) || (w>=0x30 && w<=0x39) ) { if (w>=0x41 && w<=0x46) d = 10+w-0x41; else if (w>=0x61 && w<=0x66) d = 10+w-0x61; else d = w-0x30; if (n1==88) // if wait for first code from pair { n1 = d; w1 = w; continue; } else // if wait for 2nd code from pair { n2 = d; w = n1*16 +n2; n1 = 99; n2 = 99; //skip waiting for code pair goto WRT; } } else // it turned out to be not a code pair ! { if (hexsmb!='\\') { m2[ads++] = hexsmb; // we return '=' if (n1<88) m2[ads++] = w1; // and the first code if any } if (w==ordhex) { n1 = 88; n2 = 88; n0 = 0; continue; } // start waiting for new code pair else if (hexsmb=='\\') continue; else { n1 = 99; n2 = 99; goto WRT; } } } WRT: m2[ads++] = w; } if (n2==88) // if string finished when we wait for code pair { m2[ads++] = hexsmb; // we return '=' if (hexsmb=='\\') m2[ads++] = 39; if (n1<88) m2[ads++] = w1; // and the first code if any } m2[ads++] = '\0'; return dst; }; extern void ConvertToHEX (FILE* f1, FILE* f2) { char d,ordhex; int ch, w; ordhex = hexsmb; while ( (ch=getc(f1)) != EOF ) { w = ch; if (w<0) w+= 256; //printf("w=%i, w/16=%i, w mod 16=%i\n", w,w/16,w%16); if ( w==10 || w==13 || (w>=0x30 && w<=0x39) || (w>=0x41 && w<=0x5a) || w==0x5f || (w>=0x61 && w<=0x7a) ) putc (w,f2); else { d = ordhex; putc(d,f2); d = w / 16; if (d<10) d = 0x30+d; else d = 0x37+d; putc(d,f2); d = w % 16; if (d<10) d = 0x30+d; else d = 0x37+d; putc(d,f2); } } fflush(f2); }; extern char* Win2Hex (char* src, char *dst) { char *m1,*m2; int w,d,ordhex,j, lensrc; int ads; ads = 0; m1 = src; m2 = dst; strcpy(m2,""); ordhex = hexsmb; lensrc = strlen(m1); for (j=0; j=0x30 && w<=0x39) || (w>=0x41 && w<=0x5a) || w==0x5f || (w>=0x61 && w<=0x7a) ) m2[ads++] = w; else { d = ordhex; m2[ads++] = d; d = (w / 16); if (d<10) d = 0x30+d; else d = 0x37+d; m2[ads++] = d; d = (w % 16); if (d<10) d = 0x30+d; else d = 0x37+d; m2[ads++] = d; } } m2[ads++] = '\0'; return dst; }; extern void TakeOddsFromFile (FILE* f1, FILE* f2) { int cc, ch; int /*bool*/yesno,lowpart; // {C3 D0 D1} yesno = false; while ( (ch=getc(f1)) != EOF ) { cc = ch; if (cc<0) cc +=256; lowpart = (cc<128); yesno = (yesno || lowpart); if (yesno) { putc(cc,f2); } //printf("cc=%i yesno=%i lowpart=%i\n",cc,yesno,lowpart); yesno = ! yesno; } fflush(f2); }; extern char* TakeOddsFromString (char* src, char* dst) { int i, cc; int /*bool*/ yesno,lowpart; int ads, lensrc; ads = 0; strcpy(dst,""); // {C3 D0 D1} yesno = false; lensrc = strlen(src); for (i=1; i< lensrc; i++) { cc = src[i]; if(cc<0) cc +=256; lowpart = (cc<128); yesno = (yesno || lowpart); if (yesno) dst[ads++] = src[i]; yesno = ! yesno; } dst[ads++] = '\0'; return dst; }; extern void DoMime64 (FILE* f1, FILE* f2) { int cc,ch,ads,lentrg; char *src,*trg; long lenf1; src = wrkstr_fi; ads = 0; strcpy(src,""); trg = wrkstr_fi2; fseek(f1, 0L, SEEK_END); lenf1 = ftell(f1) -1L; fseek(f1, 0L, SEEK_SET); //printf("lenf1=%li",lenf1); while ( (ch=getc(f1)) != EOF ) { cc = ch; if (cc<0) cc +=256; if (binhextag && (cc==':')) skipbyte = 0; if ( (re4pos((char)cc,mim) <0) && (ftell(f1)64) N = 64; /*otl printf("%s\n",src); */ // src[N]:=' '; // zap out the newline Nobuf = 0; for (i = 0; i< N; i++) { cc = re4pos(src[i],mim); if (cc<0) continue; if (i 0) { // printf ("src kk=%i: %s\n",kk,src); i1 = re4pos('+',src); if (i1>=1) { strncat(dst,src,i1); ads = strlen(dst); } // printf ("dst len=%i: <%s>\n",ads,dst); if (i1>=0) { strncpy (src1, src+i1+1,kk); i0 = strlen(src1); i2 = -1; for (i1=0; i1 =0) { if (src1[i2] != '-') strcpy (src, src1+i2); else strcpy (src, src1+i2+1); src1[i2] = '\0'; } else strcpy(src,""); i0 = strlen(src1); i1 = i0 % 4; if (i1>0) i1 = 4-i1; // printf("lensrc1,dlen,newlen:%i %i %i\n",i0,i1,i0+i1); for (i2=0; i2 < i1; i2++) src1[i0+i2]='A'; i0 += i1; src1[i0] = '\0'; // printf("src1 len>mim64: %i <%s>\n, src tail: <%s>\n",i0,src1,src); StringDoMime64(src1, src2); // printf("1st lensrc2,i1:%i,%i\n",strlen(src2),i1); i0 = i0 *3 /4 -i1; src2[i0] = '\0'; // " src2 [strlen(src2)-i1]='\0'; " i1 = i0 / 2; //printf("lensrc2,i1:%i,%i\n",i0,i1); for (i2 = 0; i2< i1; i2++) { cctag = src2[i2*2]; cc = src2[i2*2+1]; //printf("cctag,cc:%i %i+",cctag,cc); if (cctag==4 && cc>=0x10 && cc<=0x4f) cc += (-0x10+0xc0); else if (cctag!=0) { nnbad = 1; for (nn=0; nn< 64; nn++) if (uni_dead[nn*2]==cc && uni_dead[nn*2+1]==cctag) { cc = 0x80+nn; nnbad = 0; break; }; if (nnbad==1) cc=0x20; } ads = strlen(dst); dst[ads++] = cc; dst[ads] = '\0'; } } else { strcat(dst, src); strcpy(src,""); }; kk = strlen(src); } //while return dst; }; extern void DoExpress (FILE* f1, FILE* f2) { int cc, ch; char *src,*trg; int lensrc; long lenf1; src=wrkstr_fi; strcpy(src,""); trg=wrkstr_fi2; fseek(f1, 0L, SEEK_END); lenf1 = ftell(f1) -1L; fseek(f1, 0L, SEEK_SET); while ( (ch=getc(f1)) != EOF ) { cc = ch; if (cc<0) cc +=256; lensrc = strlen(src); if ( (cc==0x0d || cc==0x0a) && (ftell(f1)0 ) { if ( re4pos(src[lensrc-1],"�") >=0 ) continue; } src[lensrc++]=cc; src[lensrc]='\0'; if ( (lensrc>210 && cc==';') || (ftell(f1)>=lenf1) || (cc==0x0a) ) { StringExpress(src, trg); fwrite(trg,1,strlen(trg),f2); strcpy(src,""); } } // end while }; extern char* StringExpress (char* src, char* dst) { int p,ii,it, i, lenss, ads; char *ss,si[20], *ppos; ss = wrkstr_fi; strcpy(ss, src); strcpy(dst, ""); while ( strlen(ss) > 0 ) { ppos = strstr(ss,"&#"); p = (ppos==NULL) ? -1 : ppos-ss; if (p<0) { strcat(dst,ss); strcpy(ss,""); } else { if (p>=1) { strncat(dst,ss,p); lenss=strlen(ss); for(i=p; i<=lenss; i++) ss[i-p]=ss[i]; //ss:=copy(ss,p,length(ss)) }; p = re4pos(';',ss); if (p<3) { strcat(dst,ss); strcpy(ss,""); } else { strncpy (si,ss+2,p-2); ii = atoi(si); if (ii>1) { ii = 128+(ii % 128); it = 48+ii; ads=strlen(dst); dst[ads++]=it; dst[ads]='\0'; } else // no digital { strcat(dst,"&#"); strcat(dst,si); strcat(dst,";"); } lenss = strlen(ss); if (p0) { p = re4pos('<',ss); if (p<0) { strcat(dst,ss); strcpy(ss,""); } else { if (p>=1) { strncat(dst,ss,p-1); lenss=strlen(ss); for(i=p; i<=lenss; i++) ss[i-p]=ss[i]; //ss:=copy(ss,p,length(ss)) } p = re4pos('>',ss); if (p<0) { strcat(dst,ss); strcpy(ss,""); } else { lenss = strlen(ss); if (p' found after '<' } // '<' found } //while-loop return dst; }; re-0.1.orig/src/ru32fi.h0100644000000000001440000000157306760317210013667 0ustar rootusers/***** ru32fi.h *****/ #ifndef __RU32FI_DEF #define __RU32FI_DEF #include #include //#include "ru32cp.h" //#include "ru32var.h" //#include "ru32lat.h" extern char* Hex2Win (char* src, char* dst); extern char* Win2Hex (char* src, char *dst); extern void ConvertHEX (FILE* f1, FILE* f2); extern void ConvertToHEX (FILE* f1, FILE* f2); extern void TakeOddsFromFile (FILE* f1, FILE* f2); extern void DoMime64 (FILE* f1, FILE* f2); extern void DoBinHex (FILE* f1, FILE* f2); extern void DoExpress (FILE* f1, FILE* f2); extern char* TakeOddsFromString (char* src, char* dst); extern char* StringDoMime64 (char* src, char* dst); extern char* StringBinHex(char* src, char* dst); extern char* StringUtf7(char* src, char* dst); extern char* StringExpress (char* src, char* dst); extern char* DeleteTag (char* src, char* dst); #endif re-0.1.orig/src/ru32lat.c0100644000000000001440000002366406760317210014051 0ustar rootusers/***** ru32lat.c *****/ #include #include #include #include "ru32var.h" # define MAXTABLEN 10000 void InitLatinTable (void); void ReplaceSubWord (char* gr1, char* gr2, char* ssource); void SubstFromLat (char* LatinTable, char* trg); void SubstToLat (char* LatinTable, char* trg); void CreateStandardLatin (void); void CreateHtmlTable (void); void WriteToTable (char* src); void ReadFromTable(char* gr1, char* gr2); void SaveLatinFile(char* myfilename); void LoadLatinFile(char* myfilename); /* for interface: procedure ExposeCurrentInMemo(my_latin : TStrings); procedure ApplyLatinMemo(my_latin : TStrings); procedure LoadEditLatinFile(my_latin :TStrings; myfilename :String); procedure SaveEditLatinFile(my_latin :TStrings; myfilename :String); */ char* LatinTable = NULL; char* HtmlTable = NULL; int /*bool*/ isStandardLatin; char CurrentLatin [81]; char EditLatin [81]; int /*bool*/ isStandardEdit; char* StandardLatin = "__stdlat.txt"; char* CurrentTablePos; // -------------- // char wrkstr_lat[257], wrkstr_lat1[257], wrkstr_lat2[257];; /* working string buffer */ // -------------- // void InitLatinTable (void) { CreateStandardLatin(); CreateHtmlTable(); strcpy (CurrentLatin, StandardLatin); }; void ReplaceSubWord (char* gr1, char* gr2, char* ssource) { int newmax, k, lengr1, lengr2; char* cc; // printf ("replace- gr1,gr2: %s %s\n",gr1,gr2); cc = strstr (ssource, gr1); if (cc == NULL) return; lengr1 = strlen(gr1); lengr2 = strlen(gr2); newmax = 256 - (lengr2 - lengr1); if (newmax > 256) newmax = 256; while (cc != NULL) { strncpy (wrkstr_lat, ssource, newmax); wrkstr_lat[newmax] = '\0'; cc = strstr (wrkstr_lat, gr1); k = cc - wrkstr_lat; if (k > 0) strncpy (ssource, wrkstr_lat, k); ssource[k] = '\0'; strcat (ssource, gr2); strcat (ssource, cc + lengr1); cc = strstr (ssource +k +lengr2, gr1); }; }; void SubstFromLat (char* LatinTable, char* trg) { char *gr1, *gr2; // standart vars as in Win2Pol + additional variations: ju,ja etc gr1 = wrkstr_lat1; gr2 = wrkstr_lat2; CurrentTablePos = LatinTable; while (*CurrentTablePos > '\1') { ReadFromTable(gr1,gr2); ReplaceSubWord (gr1,gr2,trg); }; }; void SubstToLat (char* LatinTable, char* trg) { char *gr1, *gr2; gr1 = wrkstr_lat1; gr2 = wrkstr_lat2; CurrentTablePos = LatinTable; while (*CurrentTablePos > '\1') { ReadFromTable(gr1,gr2); ReplaceSubWord (gr2,gr1,trg); }; }; void CreateStandardLatin (void) { int tablen; // standart vars as in Win2Pol + additional variations: ju,ja etc isStandardLatin = true; isStandardEdit = true; if (LatinTable != NULL) free(LatinTable); LatinTable = (char*) malloc(1000); CurrentTablePos = LatinTable; WriteToTable ("BACbKA#"); WriteToTable ("BCE#"); WriteToTable ("Myppp#"); WriteToTable (" eto# "); WriteToTable (" ekz# "); WriteToTable (" eks# "); WriteToTable (" eshcho # "); WriteToTable ("tsya#"); WriteToTable ("tsia#"); WriteToTable ("tsja#"); WriteToTable ("otsuts#"); WriteToTable ("prisuts#"); WriteToTable ("molodets#"); WriteToTable ("dets#"); WriteToTable ("Shch#"); WriteToTable ("Ch#"); WriteToTable ("Sh#"); WriteToTable ("Yu#"); WriteToTable ("Ya#"); WriteToTable ("Iu#"); WriteToTable ("Ia#"); WriteToTable ("Ju#"); WriteToTable ("Ja#"); WriteToTable ("Yo#"); WriteToTable ("YO#"); WriteToTable ("Zh#"); WriteToTable ("E\x27#"); WriteToTable ("shch#"); WriteToTable ("ch#"); WriteToTable ("sh#"); WriteToTable ("yu#"); WriteToTable ("ya#"); WriteToTable ("iu#"); WriteToTable ("ia#"); WriteToTable ("ju#"); WriteToTable ("ja#"); WriteToTable ("yo#"); WriteToTable ("zh#"); WriteToTable ("e\x27#"); WriteToTable ("SHCH#"); WriteToTable ("CH#"); WriteToTable ("SH#"); WriteToTable ("YU#"); WriteToTable ("YA#"); WriteToTable ("IU#"); WriteToTable ("IA#"); WriteToTable ("JU#"); WriteToTable ("JA#"); WriteToTable ("ZH#"); WriteToTable ("TSYA#"); WriteToTable ("TSIA#"); WriteToTable ("TS#"); WriteToTable ("H#"); WriteToTable ("h#"); WriteToTable ("ts#"); WriteToTable ("^#"); WriteToTable ("^#"); WriteToTable ("\x27#"); WriteToTable ("\x27#"); WriteToTable ("\x01"); }; void CreateHtmlTable (void) { if (HtmlTable != NULL) free(HtmlTable); HtmlTable = (char*) malloc(1000); CurrentTablePos = HtmlTable; WriteToTable ("À#"); WriteToTable ("Á#"); WriteToTable ("Â#"); WriteToTable ("Ã#"); WriteToTable ("Ä#"); WriteToTable ("Å#"); WriteToTable ("Æ#"); WriteToTable ("Ç#"); WriteToTable ("È#"); WriteToTable ("É#"); WriteToTable ("Ê#"); WriteToTable ("Ë#"); WriteToTable ("Ì#"); WriteToTable ("Í#"); WriteToTable ("Î#"); WriteToTable ("Ï#"); WriteToTable ("Ð#"); WriteToTable ("Ñ#"); WriteToTable ("Ò#"); WriteToTable ("Ó#"); WriteToTable ("Ô#"); WriteToTable ("Õ#"); WriteToTable ("Ö#"); WriteToTable ("×#"); WriteToTable ("Ø#"); WriteToTable ("Ù#"); WriteToTable ("Ú#"); WriteToTable ("Û#"); WriteToTable ("Ü#"); WriteToTable ("Ý#"); WriteToTable ("Þ#"); WriteToTable ("ß#"); WriteToTable ("à#"); WriteToTable ("á#"); WriteToTable ("â#"); WriteToTable ("ã#"); WriteToTable ("ä#"); WriteToTable ("å#"); WriteToTable ("æ#"); WriteToTable ("ç#"); WriteToTable ("è#"); WriteToTable ("é#"); WriteToTable ("ê#"); WriteToTable ("ë#"); WriteToTable ("ì#"); WriteToTable ("í#"); WriteToTable ("î#"); WriteToTable ("ï#"); WriteToTable ("ð#"); WriteToTable ("ñ#"); WriteToTable ("ò#"); WriteToTable ("ó#"); WriteToTable ("ô#"); WriteToTable ("õ#"); WriteToTable ("ö#"); WriteToTable ("÷#"); WriteToTable ("ø#"); WriteToTable ("ù#"); WriteToTable ("ú#"); WriteToTable ("û#"); WriteToTable ("ü#"); WriteToTable ("ý#"); WriteToTable ("þ#"); WriteToTable ("ÿ#"); WriteToTable ("\x01"); }; void WriteToTable (char* src) { int i; strcpy (CurrentTablePos,src); strcat (CurrentTablePos, "\x10"); // var 1 // strcat (CurrentTablePos, "\x13\x10"); // var 2 CurrentTablePos += strlen(src)+1; }; void ReadFromTable(char* gr1, char* gr2) { char* posend1, *posend2, *posbeg2; int nbytes, maxlen; maxlen = strlen(CurrentTablePos); posend1 = strchr (CurrentTablePos,'#'); posend2 = strchr (CurrentTablePos,'\x10'); posbeg2 = (posend1 != NULL ) ? posend1+1 : CurrentTablePos ; if (posend1 == NULL) strcpy(gr1,"______??????"); else { nbytes = posend1 - CurrentTablePos; if (nbytes > 256) nbytes =256; strncpy (gr1,CurrentTablePos,nbytes); gr1[nbytes] = '\0'; } if (posend2 == NULL) strcpy(gr2,"______??????"); else { nbytes = posend2 - posbeg2; if (nbytes > 256) nbytes =256; strncpy (gr2,posbeg2,nbytes); gr2[nbytes] = '\0'; } if (posend2 != NULL && strlen(posend2) >0 ) CurrentTablePos = posend2+1; else CurrentTablePos += maxlen; }; void SaveLatinFile(char* myfilename) { FILE *f2; int maxlen; if (LatinTable == NULL) return; if ( (f2=fopen(myfilename,"wb")) == NULL ) { strcpy (wrkstr_lat,"can't open new file : "); strcat (wrkstr_lat,myfilename); re4ShowMessage (wrkstr_lat); return; } maxlen=strlen(LatinTable); fwrite (LatinTable,1,maxlen,f2); fclose (f2); }; void LoadLatinFile(char* myfilename) { FILE *f1; int maxlen; long offs; if ( (f1=fopen(myfilename,"rb")) == NULL ) { strcpy (wrkstr_lat,"can't open LatinTable-File : "); strcat(wrkstr_lat,myfilename); re4ShowMessage (wrkstr_lat); CreateStandardLatin (); strcpy (CurrentLatin, StandardLatin); } else { fseek (f1, 0L, SEEK_END); offs = ftell(f1); maxlen = (offs < MAXTABLEN) ? offs : MAXTABLEN; if (LatinTable != NULL) free(LatinTable); LatinTable = (char*) malloc(maxlen +1); fseek (f1, 0L, SEEK_SET); fread (LatinTable, 1, maxlen, f1); LatinTable[maxlen] = '\0'; fclose (f1); strcpy (CurrentLatin, myfilename); isStandardLatin = false; isStandardEdit = false; }; }; //----- for interface : -----// /* procedure LoadEditLatinFile(my_latin :TStrings; myfilename :String); begin try my_latin.LoadFromFile(myfilename); EditLatin:=myfilename; isStandardEdit:=false; except ShowMessage ('failed'); end; end; procedure SaveEditLatinFile(my_latin :TStrings; myfilename :String); begin try my_latin.SaveToFile(myfilename); EditLatin:=myfilename; except ShowMessage ('failed'); end; end; procedure ExposeCurrentInMemo(my_latin : TStrings); var gr1,gr2 : string; begin EditLatin:=CurrentLatin; my_latin.clear; LatinTable.Seek(0,soFromBeginning); while LatinTable.Position < LatinTable.Size do begin ReadFromTable(LatinTable, gr1,gr2); my_latin.add(gr1+'#'+gr2); end; end; procedure ApplyLatinMemo(my_latin : TStrings); var i,n : integer; begin LatinTable.clear; n:=my_latin.count; for i:=0 to n-1 do WriteToTable (my_latin.Strings[i]); CurrentLatin:=EditLatin; isStandardLatin:=isStandardEdit; end; */ re-0.1.orig/src/ru32lat.h0100644000000000001440000000177006760317210014050 0ustar rootusers/***** ru32lat.h *****/ #ifndef __RE32LAT_DEF #define __RE32LAT_DEF 1 void InitLatinTable (void); void ReplaceSubWord (char* gr1, char* gr2, char* ssource); void SubstFromLat (char* LatinTable, char* trg); void SubstToLat (char* LatinTable, char* trg); void CreateStandardLatin (void); void CreateHtmlTable (void); void WriteToTable (char* src); void ReadFromTable(char* gr1, char* gr2); void SaveLatinFile(char* myfilename); void LoadLatinFile(char* myfilename); /* for interface: procedure ExposeCurrentInMemo(my_latin : TStrings); procedure ApplyLatinMemo(my_latin : TStrings); procedure LoadEditLatinFile(my_latin :TStrings; myfilename :String); procedure SaveEditLatinFile(my_latin :TStrings; myfilename :String); */ extern char* LatinTable; extern char* HtmlTable; //extern int /*bool*/ isStandardLatin; //extern char CurrentLatin[]; //extern char EditLatin[]; //extern int /*bool*/ isStandardEdit; //extern char* StandardLatin = "__stdlat.txt"; #endif re-0.1.orig/src/ru32mau.c0100644000000000001440000005100606764040676014057 0ustar rootusers/****** ru32mau.c ******/ #include #include "ru32cp.h" #include "ru32var.h" #include "ru32fi.h" #include "ru32au.h" #include "ru32un.h" #define N_try2 60 #define N_try3a 118 //114+4 : 'kkkk','KKKK','MimD','iiDI' #define N_try3 152 //118+34+4 : 'kkkk','KKKK','MimD','iiDI' #define N_try4a 286 #define N_try4 366 int N_try; char *m_try [N_try4] = { //"KDKIK", "D","K","I","M","F","k","C","Y","Z", "~DK","~DK~DW~IW","KK","kk", "KD","kD","KI","kI","KM","kM", "DK","Dk","IK","Ik","MK","Mk","cF", //{'fC'- , CF+ } "KY","KZ","kY","kZ","YK","ZK","CK","Yk","Zk","Ck", "iD","ID","dI","IM","iC","DI","mD", "KDKIK","KIKDK","dMiCdiiiDI", "iY","iZ","YM","ZM","MZ" , "ImD","imD","kkk","KKK","iDI", "kkkk","KKKK","MimD","iiDI" , "KDK","KIK","KMK","kDK","kIK","kMK", "KDk","KIk","KMk","kDk","kIk","kMk", "KKD","KKI","KKM","DKK","IKK","MKK", "kkD","kkI","kkM","Dkk","Ikk","Mkk", "kiD","kID","kdI","kIM","kiC","kDI","kmD", "KiD","KID","KdI","KIM","KiC","KDI","KmD", "iDk","IDk","dIk","IMk","iCk","DIk","mDk", "iDK","IDK","dIK","IMK","iCK","DIK","mDK", "ikD","IkD","IkM","iKD","IKD","IKM", "KKY","KKZ","kkY","kkZ","YKK","ZKK","CKK","Ykk","Zkk","Ckk", "KiY","KiZ","KYM","KZM","KMZ","kiY","kiZ","kYM","kZM","kMZ", "iYK","iZK","YMK","ZMK","MZK","iYk","iZk","YMk","ZMk","MZk", "ZKM","MKZ","ZkM","MkZ" , "KKDK","KKIK","KKMK","KKDk","KKIk","KKMk", "kkDK","kkIK","kkMK","kkDk","kkIk","kkMk", "KDKK","KIKK","KMKK","KDkk","KIkk","KMkk", "kDKK","kIKK","kMKK","kDkk","kIkk","kMkk", "KDKK","KIKK","KMKK","KDKK","KIKK","KMKK", "KDkk","KIkk","KMkk","KDkk","KIkk","KMkk", "kDKK","kIKK","kMKK","kDKK","kIKK","kMKK", "kDkk","kIkk","kMkk","kDkk","kIkk","kMkk", "kkiD","kkID","kkdI","kkIM","kkiC","kkDI","kkmD", "KKiD","KKID","KKdI","KKIM","KKiC","KKDI","KKmD", "iDkk","IDkk","dIkk","IMkk","iCkk","DIkk","mDkk", "iDKK","IDKK","dIKK","IMKK","iCKK","DIKK","mDKK", "kiDk","kIDk","kdIk","kIMk","kiCk","kDIk","kmDk", "KiDk","KIDk","KdIk","KIMk","KiCk","KDIk","KmDk", "kiDK","kIDK","kdIK","kIMK","kiCK","kDIK","kmDK", "KiDK","KIDK","KdIK","KIMK","KiCK","KDIK","KmDK", "kikD","kIkD","kIkM","kiKD","kIKD","kIKM", "KikD","KIkD","KIkM","KiKD","KIKD","KIKM", "ikDk","IkDk","IkMk","iKDk","IKDk","IKMk", "ikDK","IkDK","IkMK","iKDK","IKDK","IKMK", "ikkD","IkkD","IkkM","iKKD","IKKD","IKKM", "KKKY","KKKZ","KKKI","KKKD","KKKM", "kkkY","kkkZ","kkkI","kkkD","kkkM", "YKKK","ZKKK","IKKK","DKKK","MKKK","CKKK", "Ykkk","Zkkk","Ikkk","Dkkk","Mkkk","Ckkk", "KKiY","KKiZ","KKYM","KKZM","KKMZ","kkiY","kkiZ","kkYM","kkZM","kkMZ", "iYKK","iZKK","YMKK","ZMKK","MZKK","iYkk","iZkk","YMkk","ZMkk","MZkk", "KiYK","KiZK","KYMK","KZMK","KMZK","KiYk","KiZk","KYMk","KZMk","KMZk", "kiYK","kiZK","kYMK","kZMK","kMZK","kiYk","kiZk","kYMk","kZMk","kMZk", "ZKKM","YKKM","MKKZ","ZkkM","YkkM","MkkZ", "KZKM","KZkM","kZKM","kZkM","ZKMK","ZkMK","ZKMk","ZkMk", "MKZK","MkZK","MKZk","MkZk" }; char CpiTry [256]; //i: 0-255 int ffreq0 [256]; //i: 0-255 int freqblock0 [16]; int bestblock0 [4]; int uppeset0,loweset0,freqmax0; int myauto2cpi; //, myDeepAuto; int CpimTo, CpimFrom; char SelMac[100]; // for display int plaintest =0; extern int AutoProcessFile (char* fn1, char* fn2); extern int Try_File (char* fn1, char* fn2); extern int/*bool*/ Try_File0 (FILE* f1, FILE* fn2); extern int/*bool*/ TestAutoLatin (int/*bool*/ istmp, char* m_res); extern int TestXX (int qcpi); extern int/*bool*/ TryByMacros (char* m_string); extern int/*bool*/ TestWin (void); extern int/*bool*/ TestWinPlainTxt (void); extern int/*bool*/ ConvertByBaseMacros (FILE *f1, FILE *f2, char *m_string); extern int MacroProcess (char* fn1, char* fn2, char* m_string, char isString); // isString: 's' or 'f', default: f // returns: 0-success, 1-convertion error, 2-file operation error extern void GetAutoCpi (int *Cp1, int *Cp2); extern const char* GetSelMac (void); // ---------------------------- // char wrkstr_mau [270], wrkstr_mau2[270]; /* temporary string buffers */ // ---------------------------- // extern int AutoProcessFile (char* fn1, char* fn2) // 0 -success, 1 -autocpi not detected, 2 -file operations failed { int /*bool*/ resAuto0 =2, need_double =false; int cp1,cp2, cp2user, i, cp1first, cp2first; char doublcpi[33], SelMac1st[100]; SetAuto (true); cp2user = GetAuto2Cpi(); strncpy(doublcpi, GetDublAuto(),32); resAuto0 = Try_File (fn1,fn2); // 0 -success, 1 -autocpi not detected, 2 -file operations failed cp1first=GetCp1(); cp2first=GetCp2(); //printf ("after 1st :SelMac=%s(res %i) getcp1,getcp2=%i %i\n", // SelMac,resAuto0,GetCp1(),GetCp2()); if (resAuto0==0) { // see if need double auto and do it: if ( re4pos(SelMac[0], doublcpi) > -1 ) { strncpy(SelMac1st, GetCodepageByNumber(GetCPIbyName(SelMac)),4); SelMac1st[4]='\0'; remove ("__tempre2dub.__"); rename (fn2,"__tempre2dub.__"); resAuto0 = Try_File("__tempre2dub.__",fn2); //printf ("after 2nd :SelMac=%s(res %i) getcp1,getcp2=%i %i\n", // SelMac,resAuto0,GetCp1(),GetCp2()); if (resAuto0==0) strncat(SelMac1st, SelMac,45); else { remove (fn2); rename("__tempre2dub.__",fn2); } strncpy(SelMac,SelMac1st,100); remove ("__tempre2dub.__"); resAuto0 =0; } } else remove(fn2); if (resAuto0==0) { // see if need convertion to another Cpi and do it: if (cp2user != WinCPI) { SetCp1(WinCPI); SetCp2(cp2user); remove ("__tempre2us.__"); rename (fn2,"__tempre2us.__"); resAuto0 =ProcessFile ("__tempre2us.__",fn2); //printf ("after 3rd :SelMac=%s(res %i) getcp1,getcp2=%i %i\n", // SelMac,resAuto0,GetCp1(),GetCp2()); if (resAuto0!=0) { remove (fn2); rename("__tempre2us.__",fn2); } remove ("__tempre2us.__"); resAuto0 =0; } } if (resAuto0==0) { SetCp1(cp1first); SetCp2(cp2first); } SetAuto(false); return resAuto0; } extern int Try_File (char* fn1, char* fn2) // 0 -success, 1 -autocpi not detected, 2 -file operations failed { int /*bool*/ winOK =false; FILE *f1=NULL, *f2=NULL; int cp1,cp2; // printf("Try_File <%s> -> <%s>\n",fn1,fn2); if ( (f1=fopen(fn1,"rb")) == NULL ) { strcpy (wrkstr_mau,"can't open file-from : "); strcat(wrkstr_mau,fn1); re4ShowMessage (wrkstr_mau); return 2; } if ( (f2=fopen(fn2,"wb")) == NULL ) { strcpy (wrkstr_mau,"can't open new file-to : "); strcat(wrkstr_mau,fn2); re4ShowMessage (wrkstr_mau); if (f1 != NULL) fclose(f1); return 2; } // ShowMessage ('f1='+f1+#10+'f2='+f2); SetAuto (true); winOK = Try_File0(f1,f2); SetAuto(false); GetAutoCpi(&cp1,&cp2); SetCp1(cp1); SetCp2(cp2); fin: if (f2 != NULL) fclose(f2); if (f1 != NULL) fclose(f1); return (winOK) ? 0 : 1; } extern int/*bool*/ Try_File0 (FILE* f1, FILE* f2) { int /*bool*/ winOK =false; char m_res[50]; int /*bool*/ res_add,extold,istmp = false; int i; char m_s, cc; if (GetDeepAuto()) N_try = N_try4; else N_try = N_try3; winOK = false; CpimFrom = -1; CpimTo = -1; extold = GetisExtended(); istmp = SymbolDistribution(f1); // if istmp - // successful created '_$tmpspc.tmp' - 1-st 500 chars if (isLatin()) { winOK = TestAutoLatin(istmp, m_res); if (winOK) { // GetTestRes (m_res, &CpimFrom, &CpimTo); SetCp1(CpimFrom); SetCp2(CpimTo); //printf("in LatProcessing %i-> %i,istmp=%c\n",GetCp1(),GetCp2(),(istmp)?'T':'F'); ProcessFile0 (f1,f2); } } else if ( isOdd() ) { CpimFrom = GetCPIbyName("Odd"); CpimTo = WinCPI; m_res[0] = 'O'; m_res[1] = '\0'; // letter Odd SetCp1(CpimFrom); SetCp2(CpimTo); ProcessFile0 (f1,f2); winOK = true; } else // try base macrolist { // CopyFreqs ("to_freq0"); GetFreqs (ffreq0, freqblock0, &uppeset0, &loweset0, &freqmax0); //printf("start macrolist\n"); // SetisExtended (false); // in ver.4.62 - operator is turned on ! plaintest=1; for (i = 0; i< N_try; i++) { // printf("trying %s\n",m_try[i]); winOK = TryByMacros (m_try[i]); if (winOK) { // printf("finding %s\n",m_try[i]); strcpy(m_res,m_try[i]); break; } } plaintest=0; // CopyFreqs ("from_freq0"); PutFreqs (ffreq0, freqblock0, uppeset0, loweset0, freqmax0); SetisExtended (extold); if (winOK) // successful try base macrolist { winOK = ConvertByBaseMacros (f1,f2,m_res); m_s = m_res[0]; if (m_s == macrodivlet) { if (strlen(m_res)>=3) { CpimFrom = GetCPIbyName(m_res+1); CpimTo = GetCPIbyName(m_res+2); } } else { CpimFrom = GetCPIbyName( m_res); //m_s i = m_s; if (toupperANSI(i)==i) CpimTo = WinCPI; else { CpimTo = CpimFrom; CpimFrom = WinCPI; }; } } // end successful try base else { winOK = TestText(); if (winOK) { GetTestRes (m_res, &CpimFrom, &CpimTo); SetCp1(CpimFrom); SetCp2(CpimTo); ProcessFile0 (f1,f2); } } } // end try base macrolist SetisExtended (extold); // if ( (! GetDeepAuto()) && (! winOK) ) // re4ShowMessage("Autocovertion failed. Try to set DeepAuto."); if (winOK) strcpy (SelMac, m_res); else if (CpimFrom==-1) strcpy (SelMac, "Autoconvertion failed"); if ( winOK && ( ! GetisAddList() ) ) { res_add = false; for (i = strlen(m_res)-1; i>-1; i--) if ( GetCPIbyName(m_res+i) >= CPI_STANDcount ) res_add = true; if (res_add) strcat (SelMac, " (Add)"); } return winOK; }; extern int/*bool*/ TestAutoLatin (int/*bool*/ istmp, char* m_res) { int rexx[3]; int i,j,jr,j0; int /*bool*/ winOK =false; long iexpress, iall; FILE *f1; winOK = TestLatin(); if (winOK) { GetTestRes (m_res, &CpimFrom, &CpimTo); //printf("in AutoLat Processing, CpiFrom:%s\n", GetCodepageByNumber(CpimFrom)); if ( istmp && ( CpimFrom==UuCPI || CpimFrom==PolCPI) ) { if ( (f1=fopen("_$tmpspc.tmp","rb")) == NULL ) return winOK; iexpress = filterfile("&#",f1); fseek (f1, 1L, SEEK_SET); iall = ftell(f1); if (f1 != NULL) fclose (f1); if (iexpress*14 > iall) CpimFrom = ExpressCPI; m_res[0]=GetCodepageByNumber(ExpressCPI)[0]; return winOK; } if ( istmp && ( CpimFrom==MimeCPI || CpimFrom==XxCPI) ) { mim = mim64; skipbyte = 0; rexx[0] = TestXX(MimeCPI); rexx[1] = TestXX(Utf7CPI); mim = mimxx; skipbyte = 1; rexx[2] = TestXX(XxCPI); j0 = -1; for (i = 1; i<= 4; i++) { for (j = 0; j<= 2; j++) { // find among results of TestXX for j-th Cpi-from (j=1..3): // first of all (when i=0) - rexx=0 // full success, // if not found - then rexx without flags 1000 and 100, // if not found - then rexx without flag 10, // at last (when i=4) - rexx without flag 1000. jr = rexx[j]; if (i==2) jr = jr / 100; else if (i==3) jr = (jr % 100) / 10; else if (i==4) jr = jr / 1000; if (jr==0) { j0 = j; break; }; } // end j-loop of Cpi groop if (j0>=0) break; } // end i-loop of sucsess degrees if (j0==0) CpimFrom = MimeCPI; else if (j0==1) CpimFrom = Utf7CPI; else if (j0==2) CpimFrom = XxCPI; else CpimFrom = MimeCPI; // maybe better here {CpiFrom = -1, winOK=false} ? // no!! zB we have Iso+Mime - then we have a chance in double auto m_res[0]=GetCodepageByNumber(CpimFrom)[0]; mim = mim64; skipbyte = 0; remove ("_$tmpspc.tmp"); } // end of istmp Mime/XX testing } return winOK; } extern int TestXX (int qcpi) { int i,ns,cc; char *s1,*s2; int/*bool*/ begstr; int nlo,nwin,nmic,nbad,nbad0,result,ch; FILE *f1=NULL; result = 1111; s1 = wrkstr_mau; s2 = wrkstr_mau2; nlo = 0; nwin = 0; nmic = 0; nbad = 0; if ( (f1=fopen("_$tmpspc.tmp","rb")) == NULL ) { return result; } while ( (ch = getc(f1) ) != EOF ) { ungetc (ch, f1); getnline (s1, f1, 128); if (qcpi==Utf7CPI) StringUtf7(s1,s2); else StringDoMime64(s1,s2); // tests2: ns = strlen(s2); for (i = 0; i< ns; i++) { cc = s2[i]; if(cc<0) cc+=256; if (cc==0x0a || cc==0x0d) continue; if (cc<=0x0d) nbad0++; else if (cc<32) nbad++; else if (cc<128) nlo++; else if (cc<192) nmic++; else nwin++ ; } // end tests2 } if (nwin>4*nbad) result-=1000; if (nwin>4*nmic) result-=100; if ( (nwin+nmic)>10*nbad ) result-=10; if ( (nwin+nmic+nlo+nbad+nbad0)>40 || (nbad0+nbad)==0 ) result-=1; //printf ("nwin=%i nbad=%i nmic=%i nlo=%i result=%i\n",nwin,nbad,nmic,nlo,result); return result; }; extern int/*bool*/ TryByMacros (char* m_string) { int/*bool*/ winOK =false; int n,j,i,k,Cp1,Cp2; char cc,cc1,m_s; char *scp1, *scp2, *scp1w, *scp2w, *scp1d, *scp2d; int macmac,mc1,mc2; int/*bool*/ extold,extnew; n = strlen(m_string); // macmac = 0; mc1 = 0; extold = GetisExtended(); extnew = extold; for (j = 0; j< 256; j++) CpiTry[j]=(char)j; macmac = 0; mc1 = 0; for (i = 0; i< n; i++) { m_s = m_string[i]; if (m_s==macrodivlet) { macmac = 1; continue; } Cp1 = re4pos(toupperANSI(m_s),CPILetter); if (macmac==1) { macmac=2; mc1=Cp1; extnew=(toupperANSI(m_s)==m_s); continue; } if (macmac==2) { macmac=0; mc2=Cp1; Cp1=mc1; Cp2=mc2; SetisExtended (extnew); } else if (toupperANSI(m_s)==m_s) Cp2=0; else { Cp2=Cp1; Cp1=0; } scp1 = CPI[Cp1][CPIbody]; scp2 = CPI[Cp2][CPIbody]; scp1w = CPI[Cp1][CPIBodyWin]; scp2w = CPI[Cp2][CPIBodyWin]; scp1d = CPI[Cp1][CPIBodyDos]; scp2d = CPI[Cp2][CPIBodyDos]; //printf("TryByMacros: Cp1=%i,Cp2=%i,scp1=%li,scp2=%li",Cp1,Cp2,scp1,scp2); for (j=0; j< 256; j++) { cc = CpiTry[j]; k = re4pos(cc,scp1); //printf("m_string %s : j=%i cc=%i k=%i scp2k=%i\n",m_string,j,cc,k,scp2[k]); //if (m_string[0]!='D') exit(0); if (k>-1) cc = scp2[k]; else if (GetisExtended() && (cc!='.')) { k = re4pos(cc,scp1w); if (k>-1)//and(k<=ExtCPIAutoLength) { cc1 = scp2w[k]; if (cc1!='.') cc=cc1; } else { k = re4pos(cc,scp1d); if (k>-1) {cc1 = scp2d[k]; if (cc1!='.') cc=cc1;} } }; // end extended processing CpiTry[j] = cc; }; // end j loop }; // end i loop SetisExtended (extold); // if (strcmp(m_string,"kkk")==0 || strcmp(m_string,"kkkk")==0) // for (j=190; j<256; j++) // { printf("%i ",CpiTry[j]); if(j%16==0)printf("\n");} printf("\n"); //printf("TryByMacros:\n %s\n",m_string); winOK=TestWin(); return winOK; }; extern int/*bool*/ TestWin (void) { int i; int /*bool*/ resOK =false; SymbolDistribution_for_Try(ffreq0, freqblock0, CpiTry) ; //printf(": mean- %f\n",SampleMean("")); //printf(" : min- %i\n",SampleMin("")); //printf(": max- %i\n",SampleMax("")); SelectBestBlocks (8); if (isLatin()) resOK = false; else if ( nInBest(8,4) && nInBest(9,4) && nInBest(10,4) && nInBest(11,4) ) resOK = TestWinPlainTxt(); else resOK = false; return resOK; }; extern int/*bool*/ TestWinPlainTxt (void) {/* good: "OAENITSVR:" KK : " " // RVEPKZh XYuF KKK: " " // TChERLTs IAZh KKKK: " " // FYuETMG JBTs bad: "" // FXTsChShch'^EhYhZh */ char *sGood="" , *sBad0="" , *sBad1="" , *sBad; float minGood,maxBad ; float mGood,mBad; float aGoodBad,bGoodBad; int/*bool*/ resOK =false; switch (plaintest) { case 0: aGoodBad=1.1; bGoodBad=0.0; sBad=sBad0; break; case 1: aGoodBad=1.6; bGoodBad=2.0; sBad=sBad0; break; default: aGoodBad=1.3; bGoodBad=2.0; sBad=sBad0; } minGood =(float)SampleMin(sGood); maxBad =(float)SampleMax(sBad); mGood =SampleMean(sGood); mBad =SampleMean(sBad); // printf ("TestWinPlainText- minGood=%f maxBad=%f aG %f, mB*aG %f\n", // minGood,maxBad,aGoodBad,maxBad*aGoodBad); // printf ("TestWinPlainText- mGood=%f mBad=%f\n", // mGood,mBad); resOK = (minGood > maxBad*aGoodBad) ;// && (mGood > mBad*bGoodBad); return resOK; }; extern int/*bool*/ ConvertByBaseMacros (FILE *f1, FILE *f2, char *m_string) { int i, n, Cp1, Cp2, k, ch; char cc, cc1, m_s; int macmac, mc1, mc2; int /*bool*/ extold, extnew; n = strlen(m_string); macmac = 0; mc1 = 0; extold = GetisExtended(); extnew = extold; //printf("start ConvByBaseMacros %s\n",m_string); fseek (f1, 0L, SEEK_SET); while ( (ch=getc(f1)) != EOF ) { cc = (char)ch; for (i=0; i< n; i++) { m_s = m_string[i]; if (m_s==macrodivlet) { macmac = 1; continue; } Cp1 = GetCPIbyName(m_string+i); //m_s if (macmac==1) { macmac=2; mc1=Cp1; extnew=(toupperANSI(m_s)==m_s); continue; } if (macmac==2) { macmac = 0; mc2 = Cp1; Cp1 = mc1; Cp2 = mc2; SetisExtended(extnew); } else if (toupperANSI(m_s)==m_s) Cp2=0; else { Cp2=Cp1; Cp1=0; } //if (ftell(f1)<3L) //printf("%c: %i -> %i\n",m_string[i],Cp1,Cp2); k = re4pos(cc,CPI[Cp1][CPIbody]); //printf("k=%i,cc=%i,cc1=%i\n",k,cc,(k>-1)?CPI[Cp2][CPIBodyWin][k]:cc); if (k>-1) cc = CPI[Cp2][CPIbody][k]; else if ( GetisExtended() && (cc!='.') ) { k = re4pos(cc,CPI[Cp1][CPIBodyWin]); if (k>-1) //and(k-1)//and(kfn2=%s\n",Cp1,Cp2,fn1cur,fn2); resOK = ProcessFile(fn1cur,fn2); // printf ("after step :resOK=%i\n", resOK); if (resOK != 0) { remove (fn2); break; } } // end if isFile SetisExtended (extold); // printf ("extold=%c\n", (extold)?'T':'F'); }; // end i loop remove (fn1wrk); return resOK; }; extern void GetAutoCpi (int *Cp1, int *Cp2) { (*Cp1)=CpimFrom; (*Cp2)=CpimTo; }; extern const char* GetSelMac (void) { return SelMac; } re-0.1.orig/src/ru32mau.h0100644000000000001440000000174606762471320014062 0ustar rootusers/****** ru32mau.h ******/ #ifndef __RU32MAU_DEF #define __RU32MAU_DEF //#include "ru32cp.c" //#include "ru32var.c" //#include "ru32fi.c" //#include "ru32au.c" extern int AutoProcessFile (char* fn1, char* fn2); extern int Try_File (char* fn1, char* fn2); // 0 -success, 1 -autocpi not detected, 2 -file operations failed extern int/*bool*/ Try_File0 (FILE* f1, FILE* f2); extern int/*bool*/ TestAutoLatin (int/*bool*/ istmp, char* m_res); extern int TestXX (int qcpi); extern int/*bool*/ TryByMacros (char* m_string); extern int/*bool*/ TestWin (void); extern int/*bool*/ TestWinPlainTxt (void); extern int/*bool*/ ConvertByBaseMacros (FILE *f1, FILE *f2, char *m_string); extern int MacroProcess (char* fn1, char* fn2, char* m_string, char isString); // isString: 's' or 'f', default: f // returns: 0-success, 1-convertion error, 2-file operation error extern void GetAutoCpi (int *Cp1, int *Cp2); extern const char* GetSelMac (void); #endif re-0.1.orig/src/ru32mold.c0100644000000000001440000003471706761610472014234 0ustar rootusers/****** ru32mau.c ******/ #include #include "ru32cp.h" #include "ru32var.h" #include "ru32fi.h" #include "ru32au.h" #include "ru32un.h" #define N_try2 60 #define N_try3a 118 //114+4 : 'kkkk','KKKK','MimD','iiDI' #define N_try3 152 //118+34+4 : 'kkkk','KKKK','MimD','iiDI' #define N_try4a 286 #define N_try4 366 int N_try; char *m_try [N_try4] = { //"KDKIK", "D","K","I","M","F","k","C","Y","Z", "~DK","~DK~DW~IW", "KD","kD","KI","kI","KM","kM", "DK","Dk","IK","Ik","MK","Mk","cF", //{'fC'- , CF+ } "KY","KZ","kY","kZ","YK","ZK","CK","Yk","Zk","Ck", "iD","ID","dI","IM","iC","DI","mD","kk","KK", "KDKIK","KIKDK","dMiCdiiiDI", "iY","iZ","YM","ZM","MZ" , "ImD","imD","kkk","KKK","iDI", "kkkk","KKKK","MimD","iiDI" , "KDK","KIK","KMK","kDK","kIK","kMK", "KDk","KIk","KMk","kDk","kIk","kMk", "KKD","KKI","KKM","DKK","IKK","MKK", "kkD","kkI","kkM","Dkk","Ikk","Mkk", "kiD","kID","kdI","kIM","kiC","kDI","kmD", "KiD","KID","KdI","KIM","KiC","KDI","KmD", "iDk","IDk","dIk","IMk","iCk","DIk","mDk", "iDK","IDK","dIK","IMK","iCK","DIK","mDK", "ikD","IkD","IkM","iKD","IKD","IKM", "KKY","KKZ","kkY","kkZ","YKK","ZKK","CKK","Ykk","Zkk","Ckk", "KiY","KiZ","KYM","KZM","KMZ","kiY","kiZ","kYM","kZM","kMZ", "iYK","iZK","YMK","ZMK","MZK","iYk","iZk","YMk","ZMk","MZk", "ZKM","MKZ","ZkM","MkZ" , "KKDK","KKIK","KKMK","KKDk","KKIk","KKMk", "kkDK","kkIK","kkMK","kkDk","kkIk","kkMk", "KDKK","KIKK","KMKK","KDkk","KIkk","KMkk", "kDKK","kIKK","kMKK","kDkk","kIkk","kMkk", "KDKK","KIKK","KMKK","KDKK","KIKK","KMKK", "KDkk","KIkk","KMkk","KDkk","KIkk","KMkk", "kDKK","kIKK","kMKK","kDKK","kIKK","kMKK", "kDkk","kIkk","kMkk","kDkk","kIkk","kMkk", "kkiD","kkID","kkdI","kkIM","kkiC","kkDI","kkmD", "KKiD","KKID","KKdI","KKIM","KKiC","KKDI","KKmD", "iDkk","IDkk","dIkk","IMkk","iCkk","DIkk","mDkk", "iDKK","IDKK","dIKK","IMKK","iCKK","DIKK","mDKK", "kiDk","kIDk","kdIk","kIMk","kiCk","kDIk","kmDk", "KiDk","KIDk","KdIk","KIMk","KiCk","KDIk","KmDk", "kiDK","kIDK","kdIK","kIMK","kiCK","kDIK","kmDK", "KiDK","KIDK","KdIK","KIMK","KiCK","KDIK","KmDK", "kikD","kIkD","kIkM","kiKD","kIKD","kIKM", "KikD","KIkD","KIkM","KiKD","KIKD","KIKM", "ikDk","IkDk","IkMk","iKDk","IKDk","IKMk", "ikDK","IkDK","IkMK","iKDK","IKDK","IKMK", "ikkD","IkkD","IkkM","iKKD","IKKD","IKKM", "KKKY","KKKZ","KKKI","KKKD","KKKM", "kkkY","kkkZ","kkkI","kkkD","kkkM", "YKKK","ZKKK","IKKK","DKKK","MKKK","CKKK", "Ykkk","Zkkk","Ikkk","Dkkk","Mkkk","Ckkk", "KKiY","KKiZ","KKYM","KKZM","KKMZ","kkiY","kkiZ","kkYM","kkZM","kkMZ", "iYKK","iZKK","YMKK","ZMKK","MZKK","iYkk","iZkk","YMkk","ZMkk","MZkk", "KiYK","KiZK","KYMK","KZMK","KMZK","KiYk","KiZk","KYMk","KZMk","KMZk", "kiYK","kiZK","kYMK","kZMK","kMZK","kiYk","kiZk","kYMk","kZMk","kMZk", "ZKKM","YKKM","MKKZ","ZkkM","YkkM","MkkZ", "KZKM","KZkM","kZKM","kZkM","ZKMK","ZkMK","ZKMk","ZkMk", "MKZK","MkZK","MKZk","MkZk" }; char CpiTry [256]; //i: 0-255 int ffreq0 [256]; //i: 0-255 int freqblock0 [16]; int bestblock0 [4]; int uppeset0,loweset0,freqmax0; int myauto2cpi; //, myDeepAuto; int CpimTo, CpimFrom; char SelMac[50]; // for display extern void AutoProcessFile (char* fn1, char* fn2); extern int/*bool*/ Try_File (FILE* f1, FILE* fn2); extern int TestXX (int qcpi); extern int/*bool*/ TryByMacros (char* m_string); extern int/*bool*/ TestWin (void); extern int/*bool*/ TestWinPlainTxt (void); extern int/*bool*/ ConvertByBaseMacros (FILE *f1, FILE *f2, char *m_string); extern void GetAutoCpi (int *Cp1, int *Cp2); extern char* GetSelMac (void); // ---------------------------- // char wrkstr_mau [270], wrkstr_mau2[270]; /* temporary string buffers */ // ---------------------------- // extern void AutoProcessFile (char* fn1, char* fn2) { int /*bool*/ winOK =false; FILE *f1=NULL, *f2=NULL; int cp1,cp2; if ( (f1=fopen(fn1,"rb")) == NULL ) { strcpy (wrkstr_un,"can't open file-from : "); strcat(wrkstr_un,fn1); re4ShowMessage (wrkstr_un); return; } if ( (f2=fopen(fn2,"wb")) == NULL ) { strcpy (wrkstr_un,"can't open new file-to : "); strcat(wrkstr_un,fn2); re4ShowMessage (wrkstr_un); goto fin;; } // ShowMessage ('f1='+f1+#10+'f2='+f2); SetAuto (true); winOK = Try_File(f1,f2); GetAutoCpi(&cp1,&cp2); Attr.Cp1 = cp1; Attr.Cp2 = cp2; if (!winOK) // not yeat converted ProcessFile0 (f1,f2); fin: if (f2 != NULL) fclose(f2); if (f1 != NULL) fclose(f1); } extern int/*bool*/ Try_File (FILE* f1, FILE* f2) { int /*bool*/ winOK =false; char m_res[50]; int i,j,jr,j0; int /*bool*/ res_add,extold,istmp = false; char m_s, cc; int rexx[3]; if (GetDeepAuto()) N_try = N_try4; else N_try = N_try3; winOK = false; CpimFrom = -1; CpimTo = -1; extold = GetisExtended(); myauto2cpi = GetAuto2Cpi(); istmp = SymbolDistribution(f1); /* // if istmp - // successful created '_$tmpspc.tmp' - 1-st 500 chars if (isLatin()) { winOK = TestAutoLatin(istmp); if (winOK) { GetTestRes (m_res, &CpimFrom, &CpimTo); SetCp1(CpimFrom); SetCp2(CpimTo); ProcessFile0 (f1,f2); } } else if ( isOdd() ) { CpimFrom = GetCPIbyName("Odd"); CpimTo = WinCPI; m_res[0] = 'O' /*letter Odd*/; m_res[1] = '\0'; SetCp1(CpimFrom); SetCp2(CpimTo); ProcessFile0 (f1,f2); WinOK = true; } else // try base macrolist { // CopyFreqs ("to_freq0"); GetFreqs (ffreq0, freqblock0, &uppeset0, &loweset0, &freqmax0); // SetisExtended (false); // in ver.4.62 - operator is turned on ! for (i = 0; i< N_try; i++) { winOK = TryByMacros (m_try[i]); if (winOK) { strcpy(m_res,m_try[i]); break; } } // CopyFreqs ("from_freq0"); PutFreqs (ffreq0, freqblock0, uppeset0, loweset0, freqmax0); SetisExtended (extold); if (winOK) // successful try base macrolist { winOK = ConvertByBaseMacros (f1,f2,m_res); m_s = m_res[0]; if (m_s == macrodivlet) { if (strlen(m_res)>=3) { CpimFrom = GetCPIbyName(m_res+1); CpimTo = GetCPIbyName(m_res+2); } } else { CpimFrom = GetCPIbyName( m_res); //m_s i = m_s; if (toupperANSI(i)==i) CpimTo = WinCPI; else { CpimTo = CpimFrom; CpimFrom = WinCPI; }; } } // end successful try base else { winOK = TestText(); if (winOK) { GetTestRes (m_res, &CpimFrom, &CpimTo); SetCp1(CpimFrom); SetCp2(CpimTo); ProcessFile0 (f1,f2); } } } // end try base macrolist */ SetisExtended (extold); if ( (! GetDeepAuto()) && (! winOK) ) re4ShowMessage("Autocovertion failed. Try to set DeepAuto."); if (winOK) strcpy (SelMac, m_res); else if (CpimFrom==-1) strcpy (SelMac, "Autoconvertion failed"); else if (CpimTo==WinCPI) strcpy(SelMac, GetCodepageByNumber(CpimFrom)); else { cc = (GetCodepageByNumber(CpimTo))[0]; SelMac[0] = tolowerANSI(cc); SelMac[1] = '\0'; } if ( winOK && (SelMac==m_res) && ( ! GetisAddList() ) ) { res_add = false; for (i = strlen(m_res)-1; i>-1; i--) if ( GetCPIbyName(m_res+i) >= CPI_STANDcount ) res_add = true; if (res_add) strcat (SelMac, " (Add)"); } return winOK; }; extern int/*bool*/ TestAutoLatin (int/*bool*/ istmp) { int /*bool*/ winOK =false; winOK = TestLatin(); if (winOK) { GetTestRes (m_res, &CpimFrom, &CpimTo); if ( istmp && ( CpimFrom==MimeCPI || CpimFrom==XxCPI) ) { mim = mim64; skipbyte = 0; rexx[0] = TestXX(MimeCPI); rexx[1] = TestXX(Utf7CPI); mim = mimxx; skipbyte = 1; rexx[2] = TestXX(XxCPI); j0 = 0; for (i = 1; i<= 4; i++) { for (j = 1; j<= 3; j++) { // find among results of TestXX for j-th Cpi-from (j=1..3): // first of all (when i=0) - rexx=0 // full success, // if not found - then rexx without flags 1000 and 100, // if not found - then rexx without flag 10, // at last (when i=4) - rexx without flag 1000. jr = rexx[j-1]; if (i==2) jr = jr / 100; else if (i==3) jr = (jr % 100) / 10; else if (i==4) jr = jr / 1000; if (jr==0) { j0 = j; break; }; } // end j-loop of Cpi groop if (j0>0) break; } // end i-loop of sucsess degrees if (j0==0) CpimFrom = MimeCPI; else if (j0==1) CpimFrom = Utf7CPI; else if (j0==2) CpimFrom = XxCPI; else CpimFrom = MimeCPI; // maybe better here {CpiFrom = -1, winOK=false} ? // no!! zB we have Iso+Mime - then we have a chance in double auto mim = mim64; skipbyte = 0; remove ("_$tmpspc.tmp"); } // end of istmp testing return winOK; } extern int TestXX (int qcpi) { int i,ns,cc; char *s1,*s2; int/*bool*/ begstr; int nlo,nwin,nmic,nbad,nbad0,result,ch; FILE *f1=NULL; result = 1111; s1 = wrkstr_mau; s2 = wrkstr_mau2; nlo = 0; nwin = 0; nmic = 0; nbad = 0; if ( (f1=fopen("_$tmpspc.tmp","rb")) == NULL ) { return result; } while ( (ch = getc(f1) ) != EOF ) { ungetc (ch, f1); getnline (s1, f1, 128); if (qcpi==Utf7CPI) StringUtf7(s1,s2); else StringDoMime64(s1,s2); // tests2: ns = strlen(s2); for (i = 0; i< ns; i++) { cc = s2[i]; if(cc<0) cc+=256; if (cc==0x0a || cc==0x0d) continue; if (cc<=0x0d) nbad0++; else if (cc<32) nbad++; else if (cc<128) nlo++; else if (cc<192) nmic++; else nwin++ ; } // end tests2 } //printf ("nn=%i nnbad=%i ch=%i(%c)\n", nn,nnbad,ch,ch); if (nwin>4*nbad) result-=1000; if (nwin>4*nmic) result-=100; if ( (nwin+nmic)>10*nbad ) result-=10; if ( (nwin+nmic+nlo+nbad+nbad0)>40 || (nbad0+nbad)==0 ) result-=1; return result; }; extern int/*bool*/ TryByMacros (char* m_string) { int/*bool*/ winOK =false; int n,j,i,k,Cp1,Cp2; char cc,cc1,m_s; char *scp1, *scp2, *scp1w, *scp2w, *scp1d, *scp2d; int macmac,mc1,mc2; int/*bool*/ extold,extnew; n = strlen(m_string); // macmac = 0; mc1 = 0; extold = GetisExtended(); extnew = extold; for (j = 0; j< 256; j++) CpiTry[j]=j; macmac = 0; mc1 = 0; for (i = 0; i< n; i++) { m_s = m_string[i]; if (m_s==macrodivlet) { macmac = 1; continue; } Cp1 = re4pos(toupperANSI(m_s),CPILetter); if (macmac==1) { macmac=2; mc1=Cp1; extnew=(toupperANSI(m_s)==m_s); continue; } if (macmac==2) { macmac=0; mc2=Cp1; Cp1=mc1; Cp2=mc2; SetisExtended (extnew); } else if (toupperANSI(m_s)==m_s) Cp2=1; else { Cp2=Cp1; Cp1=1; } scp1 = CPI[Cp1][CPIbody]; scp2 = CPI[Cp2][CPIbody]; scp1w = CPI[Cp1][CPIBodyWin]; scp2w = CPI[Cp2][CPIBodyWin]; scp1d = CPI[Cp1][CPIBodyDos]; scp2d = CPI[Cp2][CPIBodyDos]; for (j=0; j< 256; j++) { cc = CpiTry[j]; k = re4pos(cc,scp1); if (k>-1) cc = scp2[k]; else if (GetisExtended() && (cc!='.')) { k = re4pos(cc,scp1w); if (k>-1)//and(k<=ExtCPIAutoLength) { cc1 = scp2w[k]; if (cc1!='.') cc=cc1; } else { k = re4pos(cc,scp1d); if (k>-1) {cc1 = scp2d[k]; if (cc1!='.') cc=cc1;} } }; // end extended processing }; // end j loop CpiTry[j] = cc; }; // end i loop SetisExtended (extold); winOK=TestWin(); return winOK; }; extern int/*bool*/ TestWin (void) { int i; int /*bool*/ resOK =false; SymbolDistribution_for_Try(ffreq0, freqblock0, CpiTry) ; //printf(": mean- %f\n",SampleMean("")); //printf(" : min- %i\n",SampleMin("")); //printf(": max- %i\n",SampleMax("")); SelectBestBlocks (8); if (isLatin()) resOK = false; else if ( nInBest(8,4) && nInBest(9,4) && nInBest(10,4) && nInBest(11,4) ) resOK = TestWinPlainTxt(); else resOK = false; return resOK; }; extern int/*bool*/ TestWinPlainTxt (void) { int aGood,aBad ; int/*bool*/ resOK =false; // float s; aGood =SampleMin(""); // s =SampleMean(""); aBad =SampleMax(""); // printf ("TestWinPlainText- min %s=%i max %s=%i \n", // "",aGood,"",aBad); resOK = (aGood > aBad*1.1); return resOK; }; extern int/*bool*/ ConvertByBaseMacros (FILE *f1, FILE *f2, char *m_string) { int i, n, Cp1, Cp2, k, ch; char cc, cc1, m_s; int macmac, mc1, mc2; int /*bool*/ extold, extnew; n = strlen(m_string); macmac = 0; mc1 = 0; extold = GetisExtended(); extnew = extold; fseek (f1, 0L, SEEK_SET); while ( (ch=getc(f1)) != EOF ) { cc = (char)ch; for (i=0; i< n; i++) { m_s = m_string[i]; if (m_s==macrodivlet) { macmac = 1; continue; } Cp1 = GetCPIbyName(m_string+i); //m_s if (macmac==1) { macmac=2; mc1=Cp1; extnew=(toupperANSI(m_s)==m_s); continue; } if (macmac==2) { macmac = 0; mc2 = Cp1; Cp1 = mc1; Cp2 = mc2; SetisExtended(extnew); } else if (toupperANSI(m_s)==m_s) Cp2=1; else { Cp2=Cp1; Cp1=1; } //if (ftell(f1)<1L) //printf("%s: %i -> %i\n",m_string[i],Cp1,Cp2); k = re4pos(cc,CPI[Cp1][CPIbody]); if (k>-1) cc = CPI[Cp2][CPIbody][k]; else if ( GetisExtended() && (cc!='.') ) { k = re4pos(cc,CPI[Cp1][CPIBodyWin]); if (k>-1) //and(k-1)//and(k #include #include #include #include #include "ru32cp.h" #include "ru32var.h" #include "ru32lat.h" #include "ru32fi.h" #include "ru32au.h" #include "ru32mau.h" // message defines : #ifndef __ru32verinfo #define __ru32verinfo "0.1 (4.62 port)" #endif #ifndef __ru32datinfo #define __ru32datinfo "Russian Anywhere v0.1, 1999-2000" #endif #ifndef __ru32autinfo #define __ru32autinfo " http//tx-tx.da.ru, http//dll.da.ru" #endif #ifndef __ru32libinfo #define __ru32libinfo __ru32datinfo ", ver." __ru32verinfo "," __ru32autinfo #endif //---------------------------wrk attr buffer---------------- // ////Tattr Attr; - temporary in ru32var.c, extern :( //--------------------------- RCL32 export :---------------- // extern void InitLibrary(void); extern char* ProcessString (char* src, char* dst); extern int ProcessFile (char* fn1, char* fn2); // returns: 0-success, 1-convertion error, 2-file operation error extern void ProcessFile0 (FILE* f1, FILE* f2); extern int /*bool*/ CheckUnicodeFile (char* FileSpec, char* FileNew); //returns: 0 if no Unicode, 1 if changed from Unicode as FileNew, 2 if failed. extern int getDBFInfo (long *nrec, int *nfield, int *Linf, int* Lrec, char*date, FILE* f1); // *Linf - header length (bytes number), *Lrec - record length (bytes number) // *nrec - number of records, *nfield - number of fields, // date - last modified (y m d - 3 bytes). extern void LoadUserAlph (char* myAlph); extern void LoadUserAlphFile (char* fn); extern void LoadAddCPI (char* fn); extern void SaveAddCPI (char* fn); //---(from strman:)---// extern void ConvertViaString (FILE* f1, FILE* f2); extern char* Char2CharConvert (int cp1, int cp2, char* src); extern void ConvertFile (int SkipBytes, FILE* f1, FILE* f2); extern void ConvertDBF (FILE* f1, FILE* f2); extern char* Pol2Win (char* LatinTable, char* src, char* dst); extern char* Win2Pol (char* LatinTable, char* src, char* dst); extern void DecryptFile (char* fn1, char* fn2, char* pw); extern void EncryptFile (char* fn1, char* fn2, char* pw); //(-------------)// char wrkstr_un [270], wrkstr_un2[270], wrkstr_un3[270];; /* temporary string buffers */ //(-------------)// extern void InitLibrary(void) { InitCPIconst(); InitLatinTable(); __latrules = both; SetDelHtmlTag(true); binhextag = false; mimestr = 80; SetisExtended(false); SetVerbose(true); SetisAddList(true); SetAuto2Cpi(GetCPIbyName("Koi")); SetDeepAuto(true); SetPh(phNo); SetDBF(false); Attr.Cp1 = WinCPI; Attr.Cp2 = WinCPI; // Fn1:='noname.txt'; --------REVISE for interface // Fn2:='noname.cvr'; --------REVISE for interface Attr.autocpi = false; }; extern char* ProcessString (char* src, char* dst) { char* trg; trg = wrkstr_un; // printf("src: <%s>\n"); if (Attr.Cp1 < 0 || Attr.Cp2 < 0 || Attr.Cp1 >= CPI_STANDcount+CPI_ADDcount || Attr.Cp2 >= CPI_STANDcount+CPI_ADDcount || no2this(Attr.Cp2) || ((Attr.Cp1==PolCPI)&&(Attr.Cp2==HtmCPI)) || Attr.Cp1==Attr.Cp2 ) strcpy(dst,src); else if (Attr.Cp1==ExpressCPI) StringExpress (src,dst); else if (Attr.Cp1==MimeCPI) StringDoMime64 (src,dst); else if (Attr.Cp1==UuCPI) { mim = mimuu; skipbyte = 1; StringDoMime64 (src,dst); mim = mim64; skipbyte = 0; } else if (Attr.Cp1==XxCPI) { mim = mimxx; skipbyte = 1; StringDoMime64 (src,dst); mim = mim64; skipbyte = 0; } else if (Attr.Cp1==BinhexCPI) { mim = mimbin; skipbyte = 1; StringBinHex (src,dst); mim = mim64; skipbyte = 0; } else if (Attr.Cp1==Utf7CPI) StringUtf7 (src,dst); else if (Attr.Cp1==OddCPI) TakeOddsFromString (src,dst); else if (Attr.Cp1==HexCPI) Hex2Win (src,dst); else if (Attr.Cp2==HexCPI) Win2Hex (src,dst); else if (Attr.Cp1==GetCPIbyName("%hex")) { hexsmb = '%'; Hex2Win (src,dst); hexsmb = '='; } else if (Attr.Cp1==GetCPIbyName("\\hex")) { hexsmb= '\\'; Hex2Win (src,dst); hexsmb = '='; } else if (Attr.Cp1==PolCPI) { Pol2Win(LatinTable, src, dst); if (Attr.Cp2 != WinCPI) Char2CharConvert (WinCPI, Attr.Cp2, dst); } else if (Attr.Cp2==PolCPI) { if (Attr.Cp1 != WinCPI) { strcpy (trg, src); Char2CharConvert (Attr.Cp1, WinCPI, trg); Win2Pol (LatinTable, trg, dst); } else Win2Pol(LatinTable, src, dst); } else if (Attr.Cp1==HtmCPI) { __latrules = nochars; if (delhtmltag) { Pol2Win (HtmlTable, src, trg); DeleteTag (trg, dst); } else Pol2Win (HtmlTable, src, dst); __latrules = both; } else if (Attr.Cp2==HtmCPI) { __latrules = nochars; Win2Pol (HtmlTable, src, dst); __latrules = both; } else { strcpy (dst, src); Char2CharConvert (Attr.Cp1, Attr.Cp2, dst); } return dst; }; extern int ProcessFile (char* fn1, char* fn2) // returns: 0-success, 1-convertion error, 2-file operation error { FILE *f1=NULL, *f2=NULL; int cp1,cp2; if ( (f1=fopen(fn1,"rb")) == NULL ) { strcpy (wrkstr_un,"ProcessFile--can't open file-from : "); strcat(wrkstr_un,fn1); re4ShowMessage (wrkstr_un); return 2; } if ( (f2=fopen(fn2,"wb")) == NULL ) { strcpy (wrkstr_un,"ProcessFile--can't open new file-to : "); strcat(wrkstr_un,fn2); re4ShowMessage (wrkstr_un); if (f1 != NULL) fclose(f1); return 2; } // printf("ProcessFile: fn1=%s(%i),fn2=%s(%i)\n",fn1,Attr.Cp1,fn2,Attr.Cp2); ProcessFile0 (f1,f2); fin: if (f2 != NULL) fclose(f2); if (f1 != NULL) fclose(f1); return 0; } extern void ProcessFile0 (FILE* f1, FILE* f2) { fseek(f1,0L,SEEK_SET); if (Attr.Cp1<0 || Attr.Cp2<0 || Attr.Cp1>=CPI_STANDcount+CPI_ADDcount || Attr.Cp2>=CPI_STANDcount+CPI_ADDcount) { re4cpfile(f1,f2); goto fin;; }; if ( no2this(Attr.Cp2) || ((Attr.Cp1==PolCPI)&&(Attr.Cp2==HtmCPI)) ) { strcpy(wrkstr_un,"No convertion to "); strcat(wrkstr_un,GetCodepageByNumber(Attr.Cp2)); re4ShowMessage(wrkstr_un); re4cpfile(f1,f2); goto fin;; }; // printf ("ProcessFile0 start %i->%i\n",Attr.Cp1,Attr.Cp2); if (Attr.isDBF) ConvertDBF (f1,f2); else if (Attr.Cp1==ExpressCPI) DoExpress(f1,f2); else if (Attr.Cp1==MimeCPI) DoMime64(f1,f2); else if (Attr.Cp1==BinhexCPI) DoBinHex(f1,f2); else if (Attr.Cp1==UuCPI || Attr.Cp1==XxCPI || Attr.Cp1==Utf7CPI) ConvertViaString (f1,f2); else if (Attr.Cp1==OddCPI) TakeOddsFromFile (f1,f2); else if (Attr.Cp1==HexCPI) ConvertHEX(f1,f2); else if (Attr.Cp2==HexCPI) ConvertToHEX(f1,f2); else if (Attr.Cp1==GetCPIbyName("%hex")) { hexsmb = '%'; ConvertHEX(f1,f2); hexsmb = '='; } else if (Attr.Cp1==GetCPIbyName("\\hex")) ConvertViaString (f1,f2); else if (Attr.Cp1==PolCPI || Attr.Cp2==PolCPI) ConvertViaString (f1,f2); else if (Attr.Cp1==HtmCPI) ConvertViaString (f1,f2); else if (Attr.Cp2==HtmCPI) { htmlbreak = true; ConvertViaString (f1,f2); htmlbreak = false; } else ConvertFile(0,f1,f2); fin : if (f2 != NULL) fflush(f2); }; extern int /*bool*/ CheckUnicodeFile (char* FileSpec, char* FileNew) { FILE *f1=NULL, *f2=NULL; char cctag; int cc, ch, nn, nnbad; if ( (f1=fopen(FileSpec,"rb")) == NULL ) { strcpy (wrkstr_un,"can't open file-from : "); strcat(wrkstr_un,FileSpec); re4ShowMessage (wrkstr_un); return 2; } nn = 0; nnbad = 0; while ( (ch=getc(f1)) != EOF && nn++ < 100 ) { if ( ch < 0x20 && ch != 0x0d && ch != 0x0a ) nnbad++; //printf ("nn=%i nnbad=%i ch=%i(%c)\n", nn,nnbad,ch,ch); }; //printf ("nn=%i nnbad=%i\n", nn,nnbad); if (nnbad < nn/3) return 0 ; if ( (f2=fopen(FileNew,"wb")) == NULL ) { strcpy (wrkstr_un,"can't open new file-to : "); strcat(wrkstr_un, FileNew); re4ShowMessage (wrkstr_un); if (f1 != NULL) fclose(f1); return 2; } fseek (f1, 0L, SEEK_SET); while ( (ch=getc(f1)) != EOF ) { cc = ch; if ( (ch=getc(f1)) != EOF ) cctag = ch; else ungetc (ch, f1); if ( cctag == 4 && cc >= 0x10 && cc <= 0x4f ) cc += (-0x10 +0xc0); // convert russ.letters from Unicode to Win else if (cctag != 0) // if cctag=0 - cc is Win already. { // convert from Unicode to Win according to table nnbad = true; for (nn = 0; nn < 64; nn++) { if ( uni_dead[nn*2]==cc && uni_dead[nn*2+1]==cctag ) { cc = 0x80 +nn; nnbad = false; break; } } if (nnbad) cc = 0x20; // clean bad symbols. }; putc(cc,f2); }; if (f2 != NULL) fclose(f2); if (f1 != NULL) fclose(f1); return 1; }; extern int getDBFInfo (long *nrec, int *nfield, int *Linf, int* Lrec, char*date, FILE* f1) // *Linf - header length (bytes number), *Lrec - record length (bytes number) // *nrec - number of records, *nfield - number of fields, // date - last modified (y m d - 3 bytes). { int ch, ret; short wrd; long headend; fseek (f1, 0L, SEEK_SET); ch = getc (f1); // if ( (ch != 0x03) && (ch != 0x83) && (ch != 'F') ) return (1); fread ( date, 3, 1, f1); // date[4] ='\0'; nothing for.. - isn't string fread ( nrec, 4, 1, f1); fread ( &wrd, 2, 1, f1); *Linf = wrd; *nfield = ( (*Linf) - 33 ) / 32; fread ( &wrd, 2, 1, f1); *Lrec = wrd; /* printf("sizeint=%i,sizelong=%i,sizeshort=%i\n", sizeof(int),sizeof(long),sizeof(short)); printf("Linf=%i \n",*Linf); printf("date=%i %i %i \n",date[0],date[1],date[2]); printf("nrec=%i \n",*nrec); printf("nfield=%i \n",*nfield); */ if ((*Linf) < 33) return 1; headend = (*Linf)-1L; fseek (f1, headend, SEEK_SET); ret = 0; ch = 0; if ((ch = getc (f1)) != 0x0d) ret = 1; // printf ("ch=%i(%c) headend=%i\n",ch,ch,headend); fseek (f1, 0L, SEEK_SET); return ret; }; extern void LoadUserAlphFile (char* fn) { FILE * fi; char myAlph[270]; int cc, ch; if ( (fi=fopen(fn,"rb")) == NULL ) { strcpy (wrkstr_un,"can't open UserAlph-file: "); strcat(wrkstr_un,fn); re4ShowMessage (wrkstr_un); return; } cc = 0; while ( (ch=getc(fi)) != EOF && cc < 256) { myAlph[cc++] = (char)ch; } myAlph[cc] = '\0'; if (fi != NULL) fclose (fi); LoadUserAlph (myAlph); } extern void LoadUserAlph (char* myAlph) { char * s; int i,j,n,n0,kk; s = wrkstr_un; n = strlen(myAlph); n0=n; for (i = 0; i < n; i++) if ( myAlph[i] < '\32' && myAlph[i] >='\0' ) { // printf("clean%i %i %i\n ",i,n,n0); for (j = i; j < n; j++) myAlph[j]=myAlph[j+1]; n0--; } myAlph[n0]='\0'; // printf ("\n***tiny myAlf len old=%i new=%i\n",n,n0); strncpy (s,myAlph,64);// 64 - length of standart russian alphabet table n = strlen(s); kk = 64; if (n < kk) { for (i = n; i < kk; i++) s[i] = '.'; s[kk] = '\0'; } strncpy (CPI[UserCPI][CPIbody], s, kk); // for (i=0; i<64; i++) printf("%c-%i\n",CPI[PolCPI][CPIbody][i],CPI[UserCPI][CPIbody][i]); if (n0>64) strncpy (s, myAlph+64, ExtCPIwin); else strcpy(s,""); n = strlen(s); kk = ExtCPIwin; if (n < kk) { for (i = n; i < kk; i++) s[i] = '.'; s[kk] = '\0'; } strncpy (CPI[UserCPI][CPIBodyWin], s, kk); if (n0>64+ExtCPIwin) strncpy (s, myAlph+64+ExtCPIwin, ExtCPIdos); else strcpy(s,""); n = strlen(s); kk = ExtCPIdos; if (n < kk) { for (i = n; i < kk; i++) s[i] = '.'; s[kk] = '\0'; } strncpy (CPI[UserCPI][CPIBodyDos], s, kk); }; extern void LoadAddCPI (char* fn) { char *myAlf,*s,*s1,slet[100]; int i,j,nn,n0,n,np,cadd,c,ch,kk; FILE * fi; char divid; divid = ':'; myAlf = wrkstr_un; s = wrkstr_un2; s1 = wrkstr_un3; if ( (fi=fopen(fn,"rb")) == NULL ) { strcpy (wrkstr_un,"can't open UserAlph-file: "); strcat(wrkstr_un,fn); re4ShowMessage (wrkstr_un); return; } c = CPI_STANDcount+CPIaddNoChange; strncpy (slet, CPILetter, c); cadd = CPIaddNoChange; while ( (ch = getc(fi) ) != EOF ) { ungetc (ch, fi); if (c>=CPImax) break; getline (myAlf, fi); nn = strlen(myAlf); n0=nn; // printf("get lenAlf=%i\n",nn); for (i = 0; i < nn; i++) if ( myAlf[i] < '\32' && myAlf[i] >='\0' ) { // printf("clean%i %i %i\n ",i,nn,n0); for (j = i; j < nn; j++) myAlf[j]=myAlf[j+1]; n0--; } myAlf[n0]='\0'; // printf ("\n***tiny myAlf len old=%i new=%i\n",nn,n0); np = re4pos (divid ,myAlf); if (np<1) continue; // Cpi name not found if (myAlf[1]==macrodivlet) continue; //1st symbol in Cpi name is system reserved symbol. strncpy (s1, myAlf, np-1); // printf ("new: %s\n",s1); if (re4pos (s1[0], slet) >= 0) continue; // Cpi name is already used for (i = np+1; i <= n0; i++) myAlf[i-(np+1)] = myAlf[i]; // with str-end n0 = strlen(myAlf); //i.e. myAlf:=copy(myAlf,np+1,nn); //printf ("div1 s1=%s\n lenAlf=%i\n",s1,n0); np = re4pos (divid, myAlf); if (np <0) { myAlf[n0] = divid; myAlf[n0+1]='\0'; n0++; np = n0; } // If np<2 then continue; // Cpi russian alphabeth table not found if (np <1) strcpy(s, ""); else strncpy(s, myAlf,np-1); // for (i=0; i0) { CPI_ADDcount = cadd; c = CPI_STANDcount+CPI_ADDcount; for (i=0; i < c; i++) { CPILetter[i]=(char)toupper((CPI[i][CPIname])[0]); } CPILetter[c] = '\0'; // InitCPIdefines; SetisAddList (isAddList); // without changing AddList setting, recalculate CPIcount }; }; extern void SaveAddCPI (char* fn) { char *myAlf, *s, divid [2]; int i,c,cc,k; FILE *fo; divid[0] = ':'; divid[1] = '\0'; myAlf = wrkstr_un; s = wrkstr_un2; if ( (fo=fopen(fn,"wb")) == NULL ) { strcpy (wrkstr_un,"can't open new UserAlph-file: "); strcat(wrkstr_un,fn); re4ShowMessage (wrkstr_un); return; } cc = CPI_STANDcount+CPI_ADDcount; for (c = CPI_STANDcount /*+CPIaddNoChange*/; c < cc; c++) { strcpy (myAlf, CPI[c][CPIname]); strcat (myAlf, divid); strcat (myAlf, CPI[c][CPIbody]); strcat (myAlf, divid); strcpy (s, CPI[c][CPIBodyWin]); k = 0; for (i = 0; i < ExtCPIwin; i++) { if (s[i]!='.') k++; } if (k==0) strcpy(s, ""); //for don't write strings consisting of points only strcat (myAlf, s); strcat (myAlf, divid); strcpy (s, CPI[c][CPIBodyDos]); k = 0; for (i = 0; i < ExtCPIdos; i++) { if (s[i]!='.') k++; } if (k==0) strcpy(s, ""); //for don't write strings consisting of points only strcat (myAlf, s); putline (myAlf, fo); }; if (fo != NULL) fclose (fo); }; //--------------------------- STRMAN :---------------- // extern void ConvertViaString (FILE* f1, FILE* f2) { int ch, nbytes; nbytes = (htmlbreak) ? 14 : 120; while ( (ch = getc(f1) ) != EOF ) { ungetc (ch, f1); getnline (wrkstr_un, f1, nbytes); ProcessString (wrkstr_un, wrkstr_un2); putline (wrkstr_un2, f2); } fflush (f2); }; extern char* Char2CharConvert (int cp1, int cp2, char* src) { char *ss, cc1; int k; for (ss = src; *ss != '\0'; ss++) { k = re4pos(*ss, CPI[cp1][CPIbody]); if (k>-1) { *ss = CPI[cp2][CPIbody][k]; if (Attr.PH == phRE) { if (k=pLocation) *ss = 'p'; if (k=HLocation) *ss = 'H'; }; } else if ( isExtended && (*ss != '.') ) { k = re4pos(*ss, CPI[cp1][CPIBodyWin]); if (k>-1) { cc1 = (CPI[cp2][CPIBodyWin])[k]; if (cc1 != '.') *ss = cc1; } else { k = re4pos(*ss, CPI[cp1][CPIBodyDos]); if (k>-1) { cc1 = (CPI[cp2][CPIBodyDos])[k]; if (cc1 != '.') *ss = cc1; } } }; if (Attr.PH == phER) { if (*ss == 'p') *ss = CPI[cp2][CPIbody][pLocation]; if (*ss == 'H') *ss = CPI[cp2][CPIbody][HLocation]; }; }; return src; }; extern void ConvertFile (int SkipBytes, FILE* f1, FILE* f2) { int k,ch; char cc,cc1; long offs; offs = SkipBytes; while ( offs-- > 0 ) { if ( (ch=getc(f1)) == EOF ) break; cc = (char)ch; putc(cc,f2); } fseek(f1, (long)SkipBytes, 0L); while ( (ch=getc(f1)) != EOF ) { cc = (char)ch; k = re4pos(cc, CPI[Attr.Cp1][CPIbody]); //printf("\nConvertFile:cc=%x Body-k=%i",cc,k); if (k>-1) { cc = CPI[Attr.Cp2][CPIbody][k]; if (Attr.PH == phRE) { if (k=pLocation) cc = 'p'; if (k=HLocation) cc = 'H'; }; } else if ( isExtended && (cc != '.') ) { k = re4pos(cc, CPI[Attr.Cp1][CPIBodyWin]); //printf(" cc=%x BodyWin-k=%i",cc,k); if (k>-1) { cc1 = (CPI[Attr.Cp2][CPIBodyWin])[k]; if (cc1 != '.') cc = cc1; } else { k = re4pos(cc, CPI[Attr.Cp1][CPIBodyDos]); //printf(" cc=%x BodyDos-k=%i",cc,k); if (k>-1) { cc1 = (CPI[Attr.Cp2][CPIBodyDos])[k]; if (cc1 != '.') cc = cc1; } } }; if (Attr.PH == phER) { if (cc == 'p') cc = CPI[Attr.Cp2][CPIbody][pLocation]; if (cc == 'H') cc = CPI[Attr.Cp2][CPIbody][HLocation]; }; putc(cc,f2); } }; extern void ConvertDBF (FILE* f1, FILE* f2) { long nrec; int nfield, Linf, Lrec; char date[4]; if (getDBFInfo (&nrec, &nfield, &Linf, &Lrec, date, f1) != 0) // printf("in ConvertDBF Linf=%i\n",Linf); re4ShowMessage("file-from not a DBFfile"); else ConvertFile(Linf, f1, f2); }; extern char* Pol2Win (char* LatinTable, char* src, char* dst) { // standart vars as in Win2Pol + additional variations: ju,ja etc strcpy (dst, src); if (__latrules != norules) SubstFromLat (LatinTable, dst); if (__latrules != nochars) Char2CharConvert (PolCPI, WinCPI, dst); return dst; }; extern char* Win2Pol (char* LatinTable, char* src, char* dst) { // standart vars, except additional variations of Pol2Win: ju,ja etc strcpy (dst, src); //printf ("src: %s\n",src); if (__latrules != norules) SubstToLat(LatinTable, dst); //printf ("dst: %s\n",dst); if (__latrules != nochars) Char2CharConvert (WinCPI, PolCPI, dst); return dst; }; char* GenerateKey (const char* pwd) { char* dst; dst = (char*) malloc(3* strlen(pwd) +30); strcpy(dst,pwd); strcat(dst,"6751266784"); strcat(dst,pwd); strcat(dst,"78907896784567"); strcat(dst,pwd); return (dst); }; extern int/*bool*/ WhatDecFile (FILE* f1, long xt) { char *xx,cc; int ch, istry, i, xxlen; xx = wrkstr_un; strcpy(xx,"&**0773721166770226780037827889*00932**@"); xxlen = strlen(xx); istry = false; i = 0; fseek (f1, 0L, SEEK_SET); while ( (ch=getc(f1)) != EOF ) { cc = ch; if (!istry) { if (cc != '&') continue; else { i = 1; istry = true; continue; } } else { if (cc == '&') { i = 1; istry = true; continue; } else if (cc != xx[i]) {istry = false; i = 0; continue; } else { i++; if (i>=xxlen) break; } } // printf ("istry=%i,cc=%c,i=%i,xx[i]=%c\n",istry,cc,i,xx[i]); } return (i >= xxlen); } extern void DecryptFile1 (char* fn1, char* fn2, char* pw) { FILE *f1=NULL, *f2=NULL; char cc; int i, j, nj, ch, ix, ipwd, cc1; char *pww, *xx, *yy; long xt; if ( (f1=fopen(fn1,"rb")) == NULL ) { strcpy (wrkstr_un,"can't open file-from : "); strcat(wrkstr_un,fn1); re4ShowMessage (wrkstr_un); return; } if ( (f2=fopen(fn2,"wb")) == NULL ) { strcpy (wrkstr_un,"can't open new file-to : "); strcat(wrkstr_un,fn2); re4ShowMessage (wrkstr_un); goto fin;; } fseek (f1, 0L, SEEK_END); xt = ftell(f1); if (! WhatDecFile(f1,xt) ) goto fin; pww = GenerateKey(pw); xx = "&**0773721166770226780037827889*00932**@"; yy = wrkstr_un; nj = strlen(pww); j = 0; fseek (f1, 0L, SEEK_SET); while ( (ch=getc(f1)) != EOF ) { cc = ch; // printf("%c",cc); if (cc == '@') break; } i = 0; strcpy (yy,""); while ( (ch=getc(f1)) != EOF ) { cc = ch; // printf("%c--",cc); if (cc == '*') break; if (cc != '\\' && cc != 0x0d && cc != 0x0a) { yy[i++] = cc; yy[i]='\0'; } else if (cc == '\\' || cc == '*') { ix = atoi (yy); ipwd = pww[j]; if (ipwd <0) ipwd +=256; cc1 = ( ix ) ^ ( ipwd ); //printf("j=%i pww[j]=%c ix(yy)=%i(%s) cc1(ipwd)=%i(%i)\n",j,pww[j],ix,yy,cc1,ipwd); putc (cc1, f2); i = 0; strcpy (yy, ""); j++; j %= nj; }; }; fin : if (f2 != NULL) fclose(f2); if (f1 != NULL) fclose(f1); }; extern void EncryptFile1 (char* fn1, char* fn2, char* pw) { FILE *f1=NULL, *f2=NULL; int i, j, nj, ch, ix, ipwd, cc1; char *pww, *xx, *yy; long xt; if ( (f1=fopen(fn1,"rb")) == NULL ) { strcpy (wrkstr_un,"can't open file-from : "); strcat(wrkstr_un,fn1); re4ShowMessage (wrkstr_un); return; } if ( (f2=fopen(fn2,"wb")) == NULL ) { strcpy (wrkstr_un,"can't open new file-to : "); strcat(wrkstr_un,fn2); re4ShowMessage (wrkstr_un); goto fin;; } fseek (f1, 0L, SEEK_END); xt = ftell(f1); fseek (f1, 0L, SEEK_SET); pww = GenerateKey(pw); yy = wrkstr_un; xx = wrkstr_un2; nj = strlen(pww); j = 0; strcpy (yy, "EEXB"); fwrite (yy, 4, 1, f2); // xx:='&**0773721166770226780037827889*00932**@'; i = int( sin(xt)*100000 ); srandom(i); xt = random(); sprintf (xx, "%li", xt); strcpy(yy, "&**"); strcat(yy, xx); strcat(yy, "**@"); // printf ("yy: <%s>\n",yy); i = strlen(yy); fwrite (yy, i, 1, f2); while ( (ch=getc(f1)) != EOF ) { ix = (ch <0)? ch+256 : ch; ipwd = pww[j]; if (ipwd <0) ipwd +=256; cc1 = ( ix ) ^ ( ipwd ); sprintf (xx, "%i", cc1); strcat(xx,"\\"); i = strlen(xx); fwrite (xx, i, 1, f2); j++; j %= nj; }; strcpy (xx,"*"); strcat (xx, "&**0773721166770226780037827889*00932**@"); i = strlen(xx); fwrite (xx, i, 1, f2); fin : if (f2 != NULL) fclose(f2); if (f1 != NULL) fclose(f1); }; extern void DecryptFile (char* fn1, char* fn2, char* pw) { DecryptFile1 (fn1, fn2, pw); DecryptFile1 (fn1, "__tempredf", pw); DecryptFile1 ("__tempredf", fn2, pw); remove ("__tempredf"); } extern void EncryptFile (char* fn1, char* fn2, char* pw) { // EncryptFile1 (fn1, fn2, pw); EncryptFile1 (fn1, "__tempredf", pw); EncryptFile1 ("__tempredf", fn2, pw); remove ("__tempredf"); } re-0.1.orig/src/ru32un.h0100644000000000001440000000410207050305451013677 0ustar rootusers/***** ru32un.h *****/ // message defines: #ifndef __ru32verinfo #define __ru32verinfo "0.1 (4.62 port)" #endif #ifndef __ru32datinfo #define __ru32datinfo "Russian Anywhere v0.1, 1999-2000" #endif #ifndef __ru32autinfo #define __ru32autinfo " http//tx-tx.da.ru, http//now.at/dll" #endif #ifndef __ru32libinfo #define __ru32libinfo __ru32datinfo ", ver." __ru32verinfo "," __ru32autinfo #endif // header for ru32un.c: #ifndef __RU32UN_DEF #define __RU32UN_DEF 1 #include "ru32cp.h" #include "ru32var.h" #include "ru32lat.h" #include "ru32fi.h" //#include "ru32au.h" //#include "ru32mau.h" //--------------------------- RCL32 export :---------------- // extern void InitLibrary(void); extern char* ProcessString (char* src, char* dst); extern int ProcessFile (char* fn1, char* fn2); // returns: 0-success, 1-convertion error, 2-file operation error extern void ProcessFile0 (FILE* fn1, FILE* fn2); extern int /*bool*/ CheckUnicodeFile (char* FileSpec, char* FileNew); //returns: 0 if no Unicode, 1 if changed from Unicode as FileNew, 2 if failed. extern int getDBFInfo (long *nrec, int *nfield, int *Linf, int* Lrec, char*date, FILE* f1); // *Linf - header length (bytes number), *Lrec - record length (bytes number) // *nrec - number of records, *nfield - number of fields, // date - last modified (y m d - 3 bytes). extern void LoadUserAlph (char* myAlph); extern void LoadUserAlphFile (char* fn); extern void LoadAddCPI (char* fn); extern void SaveAddCPI (char* fn); //---(from strman:)---// extern void re4cpfile (FILE* f1, FILE* f2); extern void ConvertViaString (FILE* f1, FILE* f2); extern char* Char2CharConvert (int cp1, int cp2, char* src); extern void ConvertFile (int SkipBytes, FILE* f1, FILE* f2); extern void ConvertDBF (FILE* f1, FILE* f2); extern char* Pol2Win (char* LatinTable, char* src, char* dst); extern char* Win2Pol (char* LatinTable, char* src, char* dst); extern void DecryptFile (char* fn1, char* fn2, char* pw); extern void EncryptFile (char* fn1, char* fn2, char* pw); #endif re-0.1.orig/src/ru32var.c0100644000000000001440000001273406764040676014072 0ustar rootusers/***** ru32var.c *****/ #include #include #include #include "ru32cp.h" #define LF 0xa #ifndef __RU32VARTP_DEF #define __RU32VARTP_DEF 1 typedef enum TRul {norules,nochars,both}; // flag for Pol2Win,Win2Pol - convert char2char only, // convert with rules only, convert both with rules & char2char typedef enum TPH {phRE,phER,phNo}; typedef struct { TPH PH; int /*boolean*/ isDBF; int Cp1,Cp2; int /*boolean*/ autocpi; } TAttr; #endif TAttr Attr; TRul __latrules; int /*Boolean*/ isAddList, isExtended, isVerbose ; int /*boolean*/ htmlbreak, delhtmltag, binhextag; int skipbyte, mimestr; int auto2Cpi, DeepAuto; extern void SetPh (TPH myPh); extern void SetDBF (int /*bool*/ myDbf); extern void SetCp1 (int myCp1); extern void SetCp2 (int myCp2); extern int GetCp1 (void); extern int GetCp2 (void); //extern void SetFn1 (char* myFn1); //extern void SetFn2 (char* myFn2); extern void SetAuto (int /*bool*/ autodetect); extern void SetAuto2Cpi (int myauto2Cpi); extern int GetAuto2Cpi (void); extern void SetDeepAuto (int myDeepAuto); extern int GetDeepAuto (void); extern void SetisExtended (int myisExtended); extern int GetisExtended (void); extern void SetVerbose (int /*bool*/ myisVerb); extern int GetVerbose (int /*bool*/ myisVerb); extern void SetisAddList (int /*bool*/ myAddList); extern int GetisAddList (void); extern void SetDelHtmlTag (int /*bool*/ myDelTag); extern int /*bool*/ GetDelHtmlTag(void); extern void re4ShowMessage (char* msg); void getline (char *str, FILE *fp1); void putline (char *str, FILE *fp2); extern void re4cpfile (FILE* f1, FILE* f2); extern int re4cpnfile (char* ffrom, char* fto); extern char tolowerANSI (char cc); extern char toupperANSI (char cc); extern long filterfile (char *xx, FILE *f1); // ---------------------------- // extern void SetPh (TPH myPh) { Attr.PH =myPh; }; extern void SetDBF (int /*bool*/ myDBF) { Attr.isDBF =myDBF; }; extern void SetCp1 (int myCp1) { Attr.Cp1 =myCp1; }; extern void SetCp2 (int myCp2) { Attr.Cp2 =myCp2; }; extern int GetCp1 (void) { return Attr.Cp1; }; extern int GetCp2 (void) { return Attr.Cp2; }; extern void SetAuto (int /*bool*/ autodetect) { Attr.autocpi =autodetect; }; extern void SetAuto2Cpi(int myauto2Cpi) { auto2Cpi = myauto2Cpi; }; extern int GetAuto2Cpi(void) { return auto2Cpi; }; extern void SetDeepAuto (int myDeepAuto) { DeepAuto =myDeepAuto; }; extern int GetDeepAuto (void) { return DeepAuto; }; extern void SetisExtended (int myisExtended) { isExtended =myisExtended; }; extern int GetisExtended (void) { return isExtended; }; extern void SetVerbose (int /*bool*/ myisVerb) { isVerbose =myisVerb; }; extern int GetVerbose (int /*bool*/ myisVerb) { return isVerbose; }; extern void SetisAddList (int /*bool*/ myAddList) { /*Attr.addCpiList =myAddList;*/ isAddList =myAddList; if (myAddList) CPIcount =CPI_STANDcount+CPI_ADDcount; else CPIcount =CPI_STANDcount; }; extern int GetisAddList (void) { return isAddList; }; extern void SetDelHtmlTag (int /*bool*/ myDelTag) { delhtmltag = myDelTag; }; extern int /*bool*/ GetDelHtmlTag (void) { return delhtmltag; }; extern void re4ShowMessage (char* msg) { printf ("\n************\n** %s **\n************\n",msg); } void getline (char *str, FILE *fp1) { int c; char *p = str; while ( c = getc(fp1), (c != LF) && (c != EOF) ) if (c!=0x0d) *p++ = c; /* *p++ = c; */ *p = '\0'; } void getnline (char *str, FILE *fp1, int nbytes) { int c, i=0; char *p = str; while ( c = getc(fp1), (c != LF) && (c != EOF) && (i++ < nbytes) ) if (c!=0x0d) *p++ = c; if (c!=LF && c!=EOF) *p++ = c; *p = '\0'; } void putline (char *str, FILE *fp2) { char *c = str, cc; while (*c != '\0' /* && *c != 0xa && *c != 0xd */) putc(*c++, fp2); /*otl printf ("%c", *c); printf ("\n"); */ cc = 0x0d; putc(cc, fp2); cc = 0x0a; putc(cc, fp2); } extern void re4cpfile (FILE* f1, FILE* f2) { int ch; char cc; while ( (ch=getc(f1)) != EOF ) { cc=ch; putc(cc,f2); } } extern int re4cpnfile (char* ffrom, char* fto) { int i; remove (fto); i = rename (ffrom, fto); return i; } extern char tolowerANSI (char cc) { int i; char ci; i = cc; if (i<0) i +=256; if (i>=0xc0 && i<0xe0) i +=32; if (i>=0x41 && i<0x5b) i +=0x20; if (i>128) i-=256; ci=i; return ci; } extern char toupperANSI (char cc) { int i; char ci; i = cc; if (i<0) i +=256; if (i>=0xe0) i -=32; if (i>=0x61 && i<0x7b) i -=0x20; if (i>128) i-=256; ci=i; return ci; } extern long filterfile (char *xx, FILE *f1) { int xxlen, istry, i, ch; long filtcount; char xx1st, cc; xxlen = strlen(xx); if (xxlen<1) return 0L; else xx1st=xx[0]; istry = false; i = 0; filtcount = 0L; fseek (f1, 0L, SEEK_SET); // printf ("=======filterfile-start\n"); while ( (ch=getc(f1)) != EOF ) { cc = (char) ch; if (!istry) { if (cc != xx1st) continue; else { i = 1; istry = true; continue; } } else { if (cc == xx1st) { i = 1; istry = true; continue; } else if (cc != xx[i]) {istry = false; i = 0; continue; } else { i++; if (i==xxlen) { filtcount++; istry = false; i = 0; }; } } // printf ("istry=%i,cc=%c,i=%i,xx[i]=%c\n",istry,cc,i,xx[i]); } // printf ("filterfile: res= %li",filtcount); return (filtcount); } re-0.1.orig/src/ru32var.h0100644000000000001440000000400606764040676014070 0ustar rootusers/***** ru32var.h *****/ #ifndef __RU32VARTP_DEF #define __RU32VARTP_DEF 1 typedef enum TRul {norules,nochars,both}; // flag for Pol2Win,Win2Pol - convert char2char only, // convert with rules only, convert both with rules & char2char typedef enum TPH {phRE,phER,phNo}; typedef struct { TPH PH; int /*boolean*/ isDBF; int Cp1,Cp2; int /*boolean*/ autocpi; } TAttr; #endif #ifndef __RU32VAR_DEF #define __RU32VAR_DEF 1 #include //#include //#include //#include "ru32cp.h" #define LF 0xa extern TAttr Attr; extern TRul __latrules; extern int /*Boolean*/ isAddList, isExtended ; extern int /*boolean*/ htmlbreak, delhtmltag, binhextag; extern int skipbyte, mimestr; extern int auto_toCpi; extern void SetPh (TPH myPh); extern void SetDBF (int /*bool*/ myDbf); extern void SetCp1 (int myCp1); extern void SetCp2 (int myCp2); extern int GetCp1 (void); extern int GetCp2 (void); //extern void SetFn1 (char* myFn1); //extern void SetFn2 (char* myFn2); extern void SetAuto (int /*bool*/ autodetect); extern void SetAuto2Cpi(int myauto2Cpi); extern int GetAuto2Cpi(void); extern void SetDeepAuto (int myDeepAuto); extern int GetDeepAuto (void); extern void SetisExtended (int myisExtended); extern int GetisExtended (void); extern void SetVerbose (int /*bool*/ myisVerb); extern int GetVerbose (int /*bool*/ myisVerb); extern void SetisAddList (int /*bool*/ myAddList); extern int GetisAddList (void); extern void SetDelHtmlTag (int /*bool*/ myDelTag); extern int /*bool*/ GetDelHtmlTag(void); extern void re4ShowMessage (char* msg); void getline (char *str, FILE *fp1); void getnline (char *str, FILE *fp1, int nbytes); void putline (char *str, FILE *fp2); extern void re4cpfile (FILE* f1, FILE* f2); extern int re4cpnfile (char* ffrom, char* fto); extern char tolowerANSI (char cc); extern char toupperANSI (char cc); extern long filterfile (char *xx, FILE *f1); #endif