home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / msgdecom.zip / MSGDCOMP.CMD < prev   
OS/2 REXX Batch file  |  1997-02-08  |  11KB  |  277 lines

  1. /* $Header:   C:/PROJECT/REXX/MSGDCOMP/PVCS/MSGDCOMP.CMV   1.3   12 Nov 1995 17:11:26   Dennis Bareis  $ */
  2.  
  3. /*--- Initialization --------------------------------------------------------*/
  4. PgmVersion = "95.316";
  5. NullByte        = '00'x;
  6. CrLf            = '0D0A'x;
  7. FALSE           = 0;
  8. TRUE            = 1;
  9. MyFixDllNoExtn  = 'DB$GMSG'
  10. MyFixDll        = MyFixDllNoExtn || '.DLL';
  11. BlueWarpBugText = 'Probably truncated to 500 bytes by SysGetMessage() bug.';
  12.  
  13. /*--- Put out startup message -----------------------------------------------*/
  14. say '[]----------------------------------------------------------[]';
  15. say '| MSGDCOMP.CMD Version ' || PgmVersion || ' (C)opyright Dennis Bareis 1995 |';
  16. say '[]----------------------------------------------------------[]';
  17. say '';
  18. say 'All rights reserved.';
  19. say '';
  20. say '';
  21.  
  22. /*--- Split up the passed argument and display the info ---------------------*/
  23. Args = ARG(1);
  24. PARSE VAR Args InputFile OutputFile MsgPrefix EmptyIfOk;
  25.  
  26. /*--- Make sure an input file was specified ---------------------------------*/
  27. if  InputFile = "" then
  28. do
  29.    call SyntaxError 'Expected the name of an OS/2 message file (with extension .MSG)', 255;
  30. end;
  31.  
  32. /*--- Make sure an output file was specified ---------------------------------*/
  33. if  OutputFile = "" then
  34. do
  35.    call SyntaxError 'Expected the name of a file which is to contain the decompiled .MSG text', 254;
  36. end;
  37.  
  38. /*--- Make sure an output file was specified ---------------------------------*/
  39. if  MsgPrefix = "" then
  40. do
  41.    call SyntaxError 'Expected the message file prefix (3 characters)', 253;
  42. end;
  43. MsgPrefix = translate(MsgPrefix);
  44.  
  45. /*--- Don't want too many parms! --------------------------------------------*/
  46. if  EmptyIfOk <> "" then
  47. do
  48.    call SyntaxError 'Too many parameters', 252;
  49. end;
  50.  
  51. /*--- Output the message file prefix ----------------------------------------*/
  52. say 'Creating "' || OutputFile || '"...';
  53. address cmd '@del ' || OutputFile || ' >nul 2>&1';
  54. call lineout OutputFile, MsgPrefix;
  55.  
  56. /*--- Work out which routine we will use to retrieve messages ---------------*/
  57. call RxFuncAdd  'SysSearchPath', 'RexxUtil', 'SysSearchPath';
  58. FullDllName     = SysSearchPath('PATH', MyFixDll); /* work around to RxFunc? bugs */
  59. if FullDllName <> "" then
  60. do
  61.    /*--- We have located my DLL now register function -----------------------*/
  62.    UseSysGetMessage = 'N';
  63.    call RxFuncAdd  'DbGetMessage', FullDllName, 'DbGetMessage';
  64. end;
  65. else
  66. do
  67.    /*--- Can't find my DLL, oh well into cripple mode -----------------------*/
  68.    UseSysGetMessage = 'Y';
  69.    call RxFuncAdd  'SysGetMessage', 'RexxUtil', 'SysGetMessage';
  70.    say 'WARNING: using "SysGetMessage()" as "' || MyFixDllNoExtn || '" can' || "'t be loaded."
  71. end;
  72.  
  73. /*--- Loop around trying each message number to try and get text ---*/
  74. FirstMsgInFile          = -1;
  75. LastMsgFoundInFile      = -1;
  76. MissingMessages         = 0;
  77. TotalMessages           = 0;
  78. SysGetMessageTruncation = 0;
  79. ExitRc                  = 0;
  80. do MsgNumber = 0 to 9999
  81.    /*--- Get the message ----------------------------------------------------*/
  82.    if  UseSysGetMessage = 'Y' then
  83.        Message = SysGetMessage(MsgNumber, InputFile);
  84.    else
  85.        Message = DbGetMessage( MsgNumber, InputFile);
  86.  
  87.    /*--- See if the message existed in the message file or we have an error message ---*/
  88.    if MessageIsInFile(Message, MsgNumber) = TRUE then
  89.    do
  90.        /*--- Output 'filler' messages if required ---------------------------*/
  91.        if  FirstMsgInFile = -1 then
  92.        do
  93.            /*--- Record the 1st message number, no need to fill before it ---*/
  94.            FirstMsgInFile = MsgNumber;
  95.        end;
  96.        else
  97.        do
  98.            /*--- See if we need to fill for 'missing' message numbers -------*/
  99.            if  (MsgNumber-LastMsgFoundInFile) > 1 then
  100.            do
  101.                /*--- Need to fill in ----------------------------------------*/
  102.                do FillNumber = LastMsgFoundInFile+1 to MsgNumber-1
  103.                   MissingMessages = MissingMessages + 1;
  104.                   call lineout OutputFile, MsgPrefix || Get4Digits(FillNumber) || "?: ";
  105.                end;
  106.                call lineout OutputFile, ';';
  107.            end;
  108.        end;
  109.        LastMsgFoundInFile = MsgNumber;
  110.  
  111.        /*--- Work out message type (adjust message if prompt!) --------------*/
  112.        if  MsgNumberAttached(Message, MsgNumber) then
  113.        do
  114.            /*--- Remove the message number from the message -----------------*/
  115.            Message = substr(Message, 10);
  116.  
  117.            /*--- This was either a 'W' or 'E' type of message ---------------*/
  118.            MsgType = 'E';
  119.  
  120.  
  121.            /*--- We may need to add a "%0" if no CR + LF on end -------------*/
  122.            if  right(Message, 2) <> CrLf then
  123.                Message = Message || '%0' || Crlf;
  124.        end;
  125.        else
  126.        do
  127.            /*--- No message # on message (is this a prompt message?) --------*/
  128.            if  right(Message, 2) = CrLf then
  129.                MsgType = 'I';
  130.            else
  131.            do
  132.                /*--- Must be a prompt message -------------------------------*/
  133.                MsgType = 'P';
  134.                Message = Message || '%0' || Crlf;
  135.            end;
  136.        end;
  137.  
  138.        /*--- Output the message with the correct prefix etc -----------------*/
  139.        TotalMessages = TotalMessages + 1;
  140.        MessageNumberEtc = MsgPrefix || Get4Digits(MsgNumber) || MsgType || ": ";
  141.        call charout OutputFile, MessageNumberEtc || Message;
  142.        if  UseSysGetMessage = 'Y' then
  143.        do
  144.            /*--- Check for SysGetMessage truncating message -----------------*/
  145.            if  length(Message) = 500 then
  146.            do
  147.                /*--- Message unlikely to be exactly 500 bytes, assume truncated ---*/
  148.                say MessageNumberEtc || BlueWarpBugText || ''
  149.                call lineout OutputFile, ";WARNING: " || BlueWarpBugText;
  150.                SysGetMessageTruncation = SysGetMessageTruncation + 1;
  151.                ExitRc                  = 1;
  152.            end;
  153.        end;
  154.        call lineout OutputFile, ";";
  155.        call lineout OutputFile, ";" || copies("*", 78);
  156.        call lineout OutputFile, ";";
  157.    end;
  158.    else
  159.    do
  160.    end;
  161. end
  162.  
  163. /*--- Output a summary for the user -----------------------------------------*/
  164. if SysGetMessageTruncation <> 0 then
  165. do
  166.    /*--- Add message to end of generated file about the truncation ----------*/
  167.    call lineout OutputFile, ';';
  168.    call lineout OutputFile, ';*** ' || SysGetMessageTruncation || ' truncated messages in this file ***';
  169.    call lineout OutputFile, ';';
  170.  
  171.    /*--- Seperate the truncation messages from the summary ------------------*/
  172.    say '';
  173.    say '';
  174.    say 'SUMMARY'
  175.    say '~~~~~~~'
  176. end;
  177. say 'Total # of messages   : ' || TotalMessages;
  178. if MissingMessages <> 0 then
  179.    say 'Missing # of messages : ' || MissingMessages;
  180. say 'First Msg # In File   : ' || FirstMsgInFile;
  181. say 'Last  Msg # In File   : ' || LastMsgFoundInFile;
  182. if SysGetMessageTruncation <> 0 then
  183.    say 'Truncated messages    : ' || SysGetMessageTruncation || ' (warnings as comments in output)';
  184.  
  185. /*--- Close the file and exit -----------------------------------------------*/
  186. call lineout OutputFile;
  187. call Beep 1300,80;
  188. call Beep 1200,80;
  189. call Beep 1300,80;
  190. exit ExitRc;
  191.  
  192.  
  193.  
  194. /*===========================================================================*/
  195. Get4Digits:
  196. /*                                                                           */
  197. /* ARG(1) = Message #                                                        */
  198. /*===========================================================================*/
  199.    FourDigits = right("000" || arg(1), 4);
  200.    return(FourDigits);
  201.  
  202.  
  203. /*===========================================================================*/
  204. MsgNumberAttached:
  205. /*                                                                           */
  206. /* ARG(1) = Message Text                                                     */
  207. /* ARG(2) = Message #                                                        */
  208. /*===========================================================================*/
  209.    /*--- Work out the message # and ':' string ------------------------------*/
  210.    RightPart = Get4Digits(arg(2)) || ': ';
  211.  
  212.    /*--- Is the above in the correct location -------------------------------*/
  213.    if  substr(arg(1), 4, 6) <> RightPart then
  214.        return(FALSE);
  215.  
  216.    /*--- See if the prefix the user supplied was correct --------------------*/
  217.    if  substr(arg(1), 1, 3) <> MsgPrefix then
  218.    do
  219.        say 'ERROR: Message file prefix should have been "' || substr(Message, 1, 3) || '"';
  220.        exit 200;
  221.    end;
  222.    return(TRUE);
  223.  
  224.  
  225.  
  226. /*===========================================================================*/
  227. MessageIncludesMsgNumber:
  228. /*                                                                           */
  229. /* ARG(1) = Message Text                                                     */
  230. /* ARG(2) = Message #                                                        */
  231. /*===========================================================================*/
  232.    if mid("cannot", arg(1)) = 0 then
  233.       return(TRUE);
  234.    else
  235.        return(FALSE);
  236.  
  237.  
  238. /*===========================================================================*/
  239. MessageIsInFile:
  240. /*                                                                           */
  241. /* ARG(1) = Message Text (may be error message).                             */
  242. /* ARG(2) = Message # used to retrieve the message text.                     */
  243. /*===========================================================================*/
  244.    if  (pos("The system cannot find message  ", arg(1)) <> 0) & (pos(arg(2), arg(1)) <> 0) then
  245.        return(FALSE);          /* Error message saying message can't be loaded! */
  246.    else
  247.        return(TRUE);
  248.  
  249.  
  250.  
  251.  
  252.  
  253. /*===========================================================================*/
  254. SyntaxError:
  255. /*===========================================================================*/
  256.         say "[]-----------------------------------------------------------[]";
  257.         say "| MSGDCOMP.CMD, Version " || PgmVersion || " (C)opyright Dennis Bareis 1993 |";
  258.         say "[]-----------------------------------------------------------[]";
  259.         say "";
  260.         say "This program decompiles OS/2 message files.  This allows you to";
  261.         say "see their contents and if you have the TOOLKIT program MKMSGF.EXE";
  262.         say "then you could modify the messages and recompile it!";
  263.         say "";
  264.         say "";
  265.         say "CORRECT SYNTAX:";
  266.         say "~~~~~~~~~~~~~~";
  267.         say "   MSGDCOMP[.CMD] NameOfMsgFile NameOutOutputFile 3CharacterPrefix";
  268.         say "";
  269.         say "THE PROBLEM";
  270.         say "~~~~~~~~~~~";
  271.         Say ARG(1) || "";
  272.  
  273.  
  274.         CmdRc = ARG(2); if CmdRc = "" then CmdRc = 255;
  275.         EXIT CmdRc;
  276.  
  277.