home *** CD-ROM | disk | FTP | other *** search
/ CD Shareware Magazine 1997 January / CD_shareware_1-97.iso / DOS / UTIL / TUEXPORT.ZIP / TUEXPORT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-23  |  5.5 KB  |  171 lines

  1. // =========================================================================
  2. //
  3. // TUEXPORT.C -- Allows export of user records from TBBS USERLOG.BBS file
  4. //               to a comma delimited (CSV) format file.
  5. //
  6. // -------------------------------------------------------------------------
  7. //
  8. // History:  version    Notes:
  9. //
  10. // 23-10-96  0.1     Wrote user export utility
  11. //
  12. // -------------------------------------------------------------------------
  13. //
  14. // NOTE: DONT try compiling and using this with word alignment on...
  15. // it don't go...make sure this is off in the compiler options....
  16. //
  17. // =========================================================================
  18.  
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <conio.h>
  22. #include <string.h>
  23. #include <io.h>
  24. #include <time.h>
  25. #include "tbbs_2.h"
  26.  
  27. USERLOG    tusers;
  28.  
  29. long filesize(FILE *stream)
  30. {
  31.    long filepos,length;
  32.  
  33.    filepos = ftell(stream);
  34.    fseek(stream, 0L, SEEK_END);
  35.    length = ftell(stream);
  36.    fseek(stream, filepos, SEEK_SET);
  37.    return length;
  38. }
  39.  
  40. void main()
  41. {
  42.     long filelength;
  43.     fpos_t filepos;
  44.     int x;
  45.     FILE *TBBS_USERS,*USER_RPT;
  46.     char buf[512],password[9],notes[65];
  47.  
  48.     clrscr();
  49.     x = 0;
  50.  
  51.     printf("TBBS user base export utility, version 0.1, 23rd October 1996\n");
  52.     printf("Copyright (c) Robert Dyball, 1996  email: bob.dyball@dse.com.au \n\n");
  53.  
  54. // -------------------------------------------------------------------------
  55. // open up for input the TBBS userlog.bbs users file, this is hard wired
  56. // to assume this is in the C:\TBBS directory.
  57. // -------------------------------------------------------------------------
  58.  
  59.     if ((TBBS_USERS = fopen("c:\\tbbs\\userlog.bbs", "r+b")) == NULL) {
  60.     printf("Error opening TBBS USERLOG.BBS file for reading\n");
  61.     exit(0);
  62.     };
  63.  
  64.     filelength = filesize(TBBS_USERS);
  65.  
  66. // ---------- move to the beginning of the input file ----------------------
  67.  
  68.     fseek(TBBS_USERS, SEEK_SET, 0);
  69.  
  70.     filepos=0L;
  71.  
  72. // -------------------------------------------------------------------------
  73. // open up output file, hard wired at this stage to USER_RPT.CSV in current
  74. // directory that the utility is ran from.
  75. // -------------------------------------------------------------------------
  76.  
  77.     if ((USER_RPT = fopen("user_rpt.csv", "w+b")) == NULL) {
  78.         printf("Error opening User list output file for writing\n");
  79.         exit(0);
  80.     };
  81.  
  82.  
  83.     printf("╔═════════════════════╤═══════╤══════════════════════════════════════════╗\n");
  84.     printf("║ Exporting record #: │       │                                          ║\n");
  85.     printf("╚═════════════════════╧═══════╧══════════════════════════════════════════╝\n");
  86.  
  87.     do {
  88.  
  89.     gotoxy(5,15);
  90.  
  91. // ---------------- report the file pointer position ----------------------
  92.  
  93.     fseek(TBBS_USERS, filepos,SEEK_SET);
  94.  
  95.  
  96. // ---------------- read the data -----------------------------------------
  97.  
  98.     fread(&tusers, 512, 1, TBBS_USERS);
  99.  
  100. // ------------------------------------------------------------------------
  101. // print on screen a part of the user record being read, so as to show the
  102. // progress through the user log.
  103. // ------------------------------------------------------------------------
  104.  
  105.     gotoxy(25,5);
  106.     printf("%05d │ %-035s", x, tusers.name_locn );
  107.     x++;
  108.  
  109.  
  110. // ------------------------------------------------------------------------
  111. // extract password, as it is not null (0) terminated, making it a regular
  112. // C style string, with a null on the end. Maximum 8 bytes + null = 9 bytes
  113. // ------------------------------------------------------------------------
  114.  
  115.     strncpy(password,tusers.password,8);
  116.     password[8]='\0';
  117.  
  118.  
  119. // ------------------------------------------------------------------------
  120. // extract notes, as this is not null (0) terminated, to make it a regular
  121. // C style string, with a null on the end.  Max 64 bytes + null = 65 bytes
  122. // ------------------------------------------------------------------------
  123.  
  124.     strncpy(notes,tusers.notes,64);
  125.     notes[64]='\0';
  126.  
  127.  
  128.  
  129. // ------------------------------------------------------------------------
  130. // output to a comma delimited file.
  131. //
  132. // Add extra fields here, refer to the TBBS_2.H file for extra fields, if
  133. // necessary.
  134. //
  135. // If you prefer not to have inverted commas (") around each field, then
  136. // remove the \" parts from the second section of the fprintf statement
  137. //
  138. // The fprintf statement should be set up like:
  139. //
  140. // eg,   fprintf(OUTPUT_NAME," format info \n", variables);
  141. //
  142. // the \n is to add a carriage return to each line, the " " are needed in
  143. // the format section.
  144. //
  145. // ------------------------------------------------------------------------
  146.  
  147.  
  148.     fprintf(USER_RPT,"\"%05ld\",\"%-50s\",\"%02i\",\"%02i\",\"%02i\",\"%-8s\",\"%-64s\"\n", filepos/512, tusers.name_locn, tusers.expiration.dd, tusers.expiration.mm, tusers.expiration.yy,password,tusers.notes);
  149.  
  150.  
  151. // ------------------------------------------------------------------------
  152. // Move to the next block of data in the user log.
  153. // ------------------------------------------------------------------------
  154.  
  155.     filepos=ftell(TBBS_USERS);
  156.  
  157.     } while (filepos<filelength);
  158.  
  159. // ------------------------------------------------------------------------
  160. // Close up files, print a "I'm finished message" ..... that's all folks.
  161. // ------------------------------------------------------------------------
  162.  
  163.  
  164.     fclose(TBBS_USERS);
  165.     fclose(USER_RPT);
  166.  
  167.     printf ("\n\n\n\nExport of TBBS user file USERLOG.BBS has been completed.\n\n");
  168.  
  169. }
  170.  
  171.