home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / hlp2inf.zip / HLP2INF.C next >
C/C++ Source or Header  |  1996-01-13  |  2KB  |  89 lines

  1. #include <io.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6.    // Function Prototypes
  7.  
  8. extern int main ( int argc, char *argv[] ) ;
  9.  
  10.  
  11.    // Main Program
  12.  
  13. extern int main ( int argc, char *argv[] ) {
  14.  
  15.    char Buffer [0x1000] ;
  16.    int BytesRead ;
  17.    int Error ;
  18.    FILE *File1, *File2 ;
  19.    char Filename [_MAX_PATH] = { 0 } ;
  20.    char Drive[_MAX_DRIVE], Dir[_MAX_DIR], Fname[_MAX_FNAME], Ext[_MAX_EXT];
  21.    char Filename2 [_MAX_PATH] ;
  22.  
  23.    while ( --argc ) {
  24.       argv ++ ;
  25.       strupr ( *argv ) ;
  26.  
  27.       if ( *argv[0] == '?' ) {
  28.      printf ( "HLP2INF: Create OS/2 INF file from OS/2 HLP file.\n"
  29.             "\n"
  30.             "Parameters:\n"
  31.         "  Filename       Name of file to convert.\n"
  32.          ) ;
  33.          return ( 0 ) ;
  34.       } /* endif */
  35.  
  36.       if ( Filename[0] == 0 ) {
  37.          strcpy ( Filename, *argv ) ;
  38.          if ( access ( Filename, 0 ) ) {
  39.             fprintf ( stderr, "ERROR: File '%s' doesn't exist.", Filename ) ;
  40.             return ( 1 ) ;
  41.          } /* endif */
  42.          continue ;
  43.       } /* endif */
  44.  
  45.       fprintf ( stderr, "ERROR: Unrecognized option '%s'.", *argv ) ;
  46.       return ( 1 ) ;
  47.  
  48.    } /* endwhile */
  49.  
  50.    _splitpath ( Filename, Drive, Dir, Fname, Ext ) ;
  51.    strcpy ( Filename2, Drive ) ;
  52.    strcat ( Filename2, Dir ) ;
  53.    strcat ( Filename2, Fname ) ;
  54.    strcat ( Filename2, ".INF" ) ;
  55.    if ( access ( Filename2, 0 ) == 0 ) {
  56.       fprintf ( stderr, "ERROR: File '%s' already exists.", Filename2 ) ;
  57.       return ( 1 ) ;
  58.    } /* endif */
  59.  
  60.    Error = 0 ;
  61.    File1 = fopen ( Filename, "rb" ) ;
  62.    if ( File1 ) {
  63.       BytesRead = fread ( Buffer, 1, sizeof(Buffer), File1 ) ;
  64.       if ( memcmp ( Buffer, "HSP\x10", 4 ) ) {
  65.      fprintf ( stderr, "ERROR: File header invalid for HLP." ) ;
  66.      Error = 1 ;
  67.       } else {
  68.      File2 = fopen ( Filename2, "wb" ) ;
  69.      if ( File2 ) {
  70.         Buffer[3] = 1 ;
  71.         while ( BytesRead ) {
  72.            fwrite ( Buffer, 1, BytesRead, File2 ) ;
  73.            BytesRead = fread ( Buffer, 1, sizeof(Buffer), File1 ) ;
  74.         } /* endwhile */
  75.         fclose ( File2 ) ;
  76.      } else {
  77.         fprintf ( stderr, "ERROR: Unable to create '%s'.", Filename2 ) ;
  78.         Error = 1 ;
  79.      } /* endif */
  80.       } /* endif */
  81.       fclose ( File1 ) ;
  82.    } else {
  83.       fprintf ( stderr, "ERROR: Unable to open '%s'.", Filename ) ;
  84.       Error = 1 ;
  85.    } /* endif */
  86.  
  87.    return ( Error ) ;
  88. }
  89.