home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mmoshead.zip / samples / mmiofmts / mmiofmts.cc < prev    next >
Text File  |  1994-02-22  |  5KB  |  244 lines

  1. //////////////////////////////////////////
  2. // mmiofmts - MMPM/2 mmio formats sample
  3. //
  4. // using emx 0.8h, mm4emx 1.0
  5. //
  6. //
  7. // Marc E.E. van Woerkom, 2/94
  8. //
  9.  
  10.  
  11. #include <os2.h>
  12.  
  13. #define  INCL_OS2MM
  14. #include <os2me.h>
  15.  
  16. #include <iostream.h>
  17. #include <iomanip.h>
  18.  
  19.  
  20. //
  21. // mmformatinfo
  22. //
  23.  
  24. class mmformatinfo {
  25.     MMFORMATINFO mmfi;
  26. public:
  27.     mmformatinfo(FOURCC IOProc=0);
  28.     MMFORMATINFO* get_addr() { return &mmfi; }
  29.     LONG          get_NameLength() { return mmfi.lNameLength; }
  30.     PSZ           get_DefaultFormatExt() { return mmfi.szDefaultFormatExt; }
  31.     FOURCC        get_IOProc() { return mmfi.fccIOProc; }
  32. };
  33.  
  34.  
  35. mmformatinfo::mmformatinfo(FOURCC IOProc=0)
  36. {
  37.     char* p = (char*) &mmfi;
  38.     for (int i=0; i<sizeof(mmfi); i++) p[i] = 0;
  39.  
  40.     mmfi.fccIOProc = IOProc;
  41. }
  42.  
  43.  
  44. //
  45. // mmio_err: translate MMIO error code into a string
  46. //
  47.  
  48. void mmio_err(ULONG rc)
  49. {
  50.     cerr << "MMIO error: ";
  51.  
  52.     char* s;
  53.  
  54.     switch (rc) {
  55.     case MMIO_SUCCESS:
  56.         s = "SUCCESS (huh?)";
  57.         break;
  58.     case MMIOERR_UNBUFFERED:
  59.         s = "UNBUFFERD";
  60.         break;
  61.     case MMIOERR_INVALID_HANDLE:
  62.         s = "INVALID HANDLE";
  63.         break;
  64.     case MMIOERR_INVALID_PARAMETER:
  65.         s = "INVALID PARAMETER";
  66.         break;
  67.     case MMIOERR_READ_ONLY_FILE:
  68.         s = "READ ONLY FILE";
  69.         break;
  70.     case MMIOERR_WRITE_ONLY_FILE:
  71.         s = "WRITE ONLY FILE";
  72.         break;
  73.     case MMIOERR_WRITE_FAILED:
  74.         s = "WRITE FAILED";
  75.         break;
  76.     case MMIOERR_READ_FAILED:
  77.         s = "READ FAILED";
  78.         break;
  79.     case MMIOERR_SEEK_FAILED:
  80.         s = "SEEK FAILED";
  81.         break;
  82.     case MMIOERR_NO_FLUSH_NEEDED:
  83.         s = "NO FLUSH NEEDED";
  84.         break;
  85.     case MMIOERR_OUTOFMEMORY:
  86.         s = "OUT OF MEMORY";
  87.         break;
  88.     case MMIOERR_CANNOTEXPAND:
  89.         s = "CANNOT EXPAND";
  90.         break;
  91.     case MMIOERR_FREE_FAILED:
  92.         s = "FREE FAILED";
  93.         break;
  94.     case MMIOERR_CHUNKNOTFOUND:
  95.         s = "CHUNK NOT FOUND";
  96.         break;
  97.     case MMIO_ERROR:
  98.         s = "ERROR";
  99.         break;
  100.     case MMIO_WARNING:
  101.         s = "WARNING";
  102.         break;
  103.     case MMIO_CF_FAILURE:
  104.         s = "CF FAILURE";
  105.         break;
  106.     default:
  107.         cerr << rc;
  108.         s = " (hmm...)";
  109.     }
  110.  
  111.     cerr << s << "\n";
  112. }
  113.  
  114.  
  115. //
  116. // main procedure
  117. //
  118. //
  119. // WARNING: The MMPM/2 stops working on my system
  120. //          if I use a string as argument for the FOURCC mask
  121. //          which is none of the registered ones! (e.g. wuff)
  122. //
  123. //          Looks like a MMPM/2 bug to me.
  124. //          (A major confusion of mmio.dll?)
  125. //
  126.  
  127. int main(int argc, char* argv[])
  128. {
  129.     cout << "mmiofmts -- MMPM/2 MMIO Formats\n\n";
  130.  
  131.  
  132.     // parse args
  133.  
  134.     FOURCC mask = 0;
  135.  
  136.     if (argc>1) {
  137.         mask = mmioStringToFOURCC(argv[1], MMIO_TOUPPER);
  138.  
  139.         cout << "mask in use is [";
  140.         char* p = (char*) &mask;
  141.         for (int i=0; i<4; i++) cout << p[i];
  142.         cout << "]\n\n";
  143.     }
  144.  
  145.  
  146.     // query # of IOProcedures
  147.  
  148.     mmformatinfo mmfi_spec(mask);
  149.  
  150.     ULONG NumFormats = 0;
  151.  
  152.     ULONG rc = mmioQueryFormatCount(mmfi_spec.get_addr(),
  153.                                     &NumFormats,
  154.                                     0,
  155.                                     0);
  156.  
  157.     if (rc != MMIO_SUCCESS) {
  158.         mmio_err(rc);
  159.         return 1;
  160.     }
  161.  
  162.     cout << "formats supported: " << NumFormats;
  163.  
  164.     if (!NumFormats) return 0;
  165.  
  166.  
  167.     // get formats
  168.  
  169.     mmformatinfo* mmfip = new mmformatinfo[NumFormats];
  170.  
  171.     ULONG FormatsRead = 0;
  172.  
  173.     rc = mmioGetFormats(mmfi_spec.get_addr(),
  174.                         NumFormats,
  175.                         mmfip,
  176.                         &FormatsRead,
  177.                         0,
  178.                         0);
  179.  
  180.     if (rc != MMIO_SUCCESS) {
  181.         mmio_err(rc);
  182.         return 2;
  183.     }
  184.  
  185.     cout << "  (" << FormatsRead << " formats read)\n\n";
  186.  
  187.  
  188.     // print information
  189.  
  190.     cout << "no.   4-cc   name                                     leng  extn\n\n";
  191.  
  192.     for (int i=0; i<NumFormats; i++) {
  193.         cout.setf(ios::right, ios::adjustfield);
  194.         cout << setw(2) << i+1 << ":  [";
  195.  
  196.         FOURCC IOProc = mmfip[i].get_IOProc();
  197.         char* p = (char*) &IOProc;
  198.  
  199.         for (int j=0; j<4; j++) cout << p[j];
  200.         cout << "]  ";
  201.  
  202.         LONG NameLength = mmfip[i].get_NameLength();
  203.  
  204.         if (NameLength) {
  205.             PSZ name = new CHAR[NameLength+1];
  206.             LONG BytesRead = 0;
  207.  
  208.             rc = mmioGetFormatName(mmfip[i].get_addr(),
  209.                                    name,
  210.                                    &BytesRead,
  211.                                    0,
  212.                                    0);
  213.  
  214.             name[NameLength] = 0;
  215.  
  216.             if (rc != MMIO_SUCCESS) {
  217.                 mmio_err(rc);
  218.                 cout << "     ";
  219.             }
  220.             else {
  221.                 cout.setf(ios::left, ios::adjustfield);
  222.                 cout << setw(40) << name << " ("
  223.                      << setw(2) << BytesRead;
  224.             }
  225.  
  226.             delete[] name;
  227.         }
  228.         else
  229.             cout << "-" << setw(43) << "( 0";
  230.  
  231.         cout.setf(ios::left, ios::adjustfield);
  232.         cout << ")  ."
  233.              << setw(3) << mmfip[i].get_DefaultFormatExt() << "\n";
  234.     }
  235.  
  236.     delete[] mmfip;
  237.  
  238.  
  239.     // that's all folks!
  240.  
  241.     return 0;
  242. }
  243.  
  244.