HOGFILE.C 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  12. */
  13. #include <dos.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <io.h>
  18. FILE * HogFile;
  19. void hog_add_file( char * filename )
  20. {
  21. FILE * fp;
  22. int length;
  23. char *data;
  24. int i;
  25. fp = fopen( filename, "rb" );
  26. if ( fp == NULL ) {
  27. printf( "Error opening '%s'... not added!\n", filename );
  28. fclose( HogFile );
  29. exit(1);
  30. }
  31. length = filelength(fileno(fp));
  32. data = malloc( length );
  33. if ( data == NULL ) {
  34. printf( "Error mallocing '%s'... not added!\n", filename );
  35. fclose(fp);
  36. fclose( HogFile );
  37. exit(1);
  38. }
  39. i = fread( data, length, 1, fp );
  40. if ( i != 1 ) {
  41. printf( "Error reading '%s'... not added!\n", filename );
  42. fclose(fp);
  43. free(data);
  44. fclose( HogFile );
  45. exit(1);
  46. }
  47. fclose(fp);
  48. if (fwrite( filename, 13, 1, HogFile )!=1 ) {
  49. printf("Error writing hogfile\n" );
  50. fclose( HogFile );
  51. exit(1);
  52. }
  53. if (fwrite( &length, 4, 1, HogFile)!=1 ) {
  54. printf("Error writing hogfile\n" );
  55. fclose( HogFile );
  56. exit(1);
  57. }
  58. if (fwrite( data, length, 1, HogFile)!=1 ) {
  59. printf("Error writing hogfile\n" );
  60. fclose( HogFile );
  61. exit(1);
  62. }
  63. }
  64. #define REMOVE_EOL(s) remove_char((s),'\n')
  65. #define REMOVE_COMMENTS(s) remove_char((s),';')
  66. #define REMOVE_DOTS(s) remove_char((s),'.')
  67. void remove_char( char * s, char c )
  68. {
  69. char *p;
  70. p = strchr(s,c);
  71. if (p) *p = '\0';
  72. }
  73. int main(int argc, char * argv[] )
  74. {
  75. char * id = "DHF";
  76. char inputline[160+1];
  77. char filename[80];
  78. FILE * fp;
  79. if ( argc < 3 ) {
  80. printf( "Usage: hogfile inputfile outputfile\n" );
  81. exit(1);
  82. }
  83. fp = fopen( argv[1], "rt" );
  84. if ( fp == NULL ) {
  85. printf( "Error opening '%s'\n", argv[1] );
  86. exit(1);
  87. }
  88. HogFile = fopen( argv[2], "wb" );
  89. if ( HogFile == NULL ) {
  90. printf( "Error opening '%s'\n", argv[2] );
  91. fclose(fp);
  92. exit(1);
  93. }
  94. if (fwrite( id, 3, 1, HogFile )!=1) {
  95. printf("Error writing hogfile\n" );
  96. fclose( HogFile );
  97. exit(1);
  98. }
  99. while (fgets(inputline, 160, fp )) {
  100. REMOVE_EOL(inputline);
  101. REMOVE_COMMENTS(inputline);
  102. sscanf( inputline, " %s ", filename );
  103. if ( strlen( inputline ) > 0 ) {
  104. //printf( "Adding '%s'...", filename );
  105. hog_add_file( filename );
  106. //printf( "\n" );
  107. }
  108. }
  109. fclose(fp);
  110. fclose( HogFile );
  111. return 0;
  112. }
  113.