home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Multimed / Multimed.zip / loadds7.zip / main.c < prev    next >
C/C++ Source or Header  |  1997-10-06  |  3KB  |  126 lines

  1. /*
  2.  * main.c - âüâCâôâïü[â`âô
  3.  * loadds7 by Romy, 1997
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8.  
  9. #define INCL_DOS
  10. #include <os2.h>
  11.  
  12. #include "serial.h"
  13. #include "ds7.h"
  14. #include "messages.h"
  15.  
  16. int
  17. main( int argc, char* argv[] )
  18. /* ê°é½Éö: argv[1]..COMâ|ü[âgö╘ìå, argv[2]..â{ü[âîü[âg,
  19.            argv[3]-..ĵéΦì₧é▐ëµæ£ö╘ìå */
  20. {
  21.     HFILE hFile;
  22.     CHAR sTmp[80];
  23.     INT i, nImages;
  24.     USHORT usBaud = 9600;    /*Åëè·Æ╩ÉMæ¼ôxé═9600â{ü[*/
  25.     CHAR *asFilename;
  26.  
  27.     /*âoü[âWâçâôò\Ī*/
  28.     fprintf( stderr, msg_Version );
  29.  
  30.     if( argc < 2 ){
  31.         /*âwâïâvò\Ī*/
  32.         fprintf( stderr, msg_Usage, argv[0] );
  33.         return 0;
  34.     }
  35.  
  36.     /*COMâ|ü[âgé╠Åëè·ë╗*/
  37.     if( COM_Init(atoi(argv[1]), &hFile) != 0 ){
  38.         fprintf( stderr, msg_CantOpenCom, atoi(argv[1]) );
  39.         return -1;
  40.     }
  41.  
  42.     /*É┌æ▒ùvïü*/
  43.     if( StartConnection( hFile ) != 0 || Resp(hFile) != ACK ){
  44.         fprintf( stderr, msg_CantStartConn );
  45.         COM_Close( hFile );
  46.         return -1;
  47.     }
  48.     SendACK( hFile );
  49.  
  50.     /*âJâüâëÅεò±é╠ĵô╛*/
  51.     if( GetCameraInfo( hFile, sTmp ) != 0 ){
  52.         fprintf( stderr, msg_CantGetCamInfo );
  53.         EndConnection( hFile );
  54.         COM_Close( hFile );
  55.         return -1;
  56.     }
  57.  
  58.     /*ïLÿ^ûçÉöé╠ĵô╛*/
  59.     nImages = GetRecordInfo( hFile );
  60.     if( nImages == 0 ){
  61.         /*ëµæ£é¬â[âìé╚éτÅIù╣*/
  62.         fprintf( stderr, msg_CantGetImageNum );
  63.         EndConnection( hFile );
  64.         COM_Close( hFile );
  65.         return -1;
  66.     }
  67.     else if( nImages < 0 ){
  68.         /*ëµæ£ûçÉöé¬Äµô╛é┼é½é╚é»éΩé╬ÅIù╣*/
  69.         fprintf( stderr, msg_CantGetImageNum );
  70.         EndConnection( hFile );
  71.         COM_Close( hFile );
  72.         return -1;
  73.     }
  74.     fprintf( stderr, msg_CamInfo, sTmp+5, nImages );
  75.  
  76.     /*Æ╩ÉMæ¼ôxâIâvâVâçâôé╠ô╟é▌ĵéΦ*/
  77.     if( argc > 2 ){
  78.         usBaud = atoi( argv[2] );
  79.     }
  80.  
  81.     /*Æ╩ÉMæ¼ôxÉ▌ÆΦ*/
  82.     if( ChangeBaudrate( hFile, usBaud ) != 0 ){
  83.         fprintf( stderr, msg_CantChangeBaud );
  84.         EndConnection( hFile );
  85.         COM_Close( hFile );
  86.         return -1;
  87.     }
  88.  
  89.     /*ëµæ£ö╘ìåÄwÆΦé¬éáéΩé╬ëµæ£Ä≤ÉM*/
  90.     if( argc > 3 ){
  91.         /*ê°Éöé┼ÄwÆΦé│éΩé╜ö╘ìåé╠ëµæ£é≡Åçé╔Ä≤ÉM*/
  92.         for( i = 3; i < argc; i++ ){
  93.             if( atoi(argv[i]) > 0 ){
  94.                 if( GetImageName( hFile, atoi(argv[i]), sTmp ) == 0 ){
  95.                     fprintf( stdout, msg_Receiving, atoi(argv[i]), sTmp );
  96.                     if( GetImage( hFile, atoi(argv[i]), sTmp ) != 0 ){
  97.                         fprintf( stderr, msg_CantGetImage, atoi(argv[i]) );
  98.                     }
  99.                 }
  100.             }
  101.         }
  102.     }
  103.     /*ëµæ£ö╘ìåÄwÆΦé¬é╚é»éΩé╬ëµæ£âtâ@âCâïû╝ò\Ī*/
  104.     else{
  105.         asFilename = (CHAR*)malloc( 13*nImages );
  106.         for( i = 1; i <= nImages; i++ ){
  107.             fprintf( stderr, "%d\r", i );
  108.             if( GetImageName( hFile, i, sTmp ) == 0 ){
  109.                 strcpy( asFilename+13*(i-1), sTmp );
  110.             }
  111.             else{
  112.                 strcpy( asFilename+13*(i-1), "N/A" );
  113.             }
  114.         }
  115.         for( i = 0; i < nImages; i++ ){
  116.             fprintf( stdout, "No.%2d:%s\n", i+1,asFilename+13*i );
  117.         }
  118.         free( asFilename );
  119.     }
  120.  
  121.     EndConnection( hFile );
  122.     COM_Close( hFile );
  123.  
  124.     return 0;
  125. }
  126.