home *** CD-ROM | disk | FTP | other *** search
/ Network CD 2 / Network CD - Volume 2.iso / ncomm / pbview / pbview.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-03  |  3.1 KB  |  112 lines

  1. /* PbView for use with NComm V1.9 or later */
  2. /*  Displays an NComm phonebook file in a  */
  3. /*  very ugly and badly formatted way :-)  */
  4. /*  Public Domain by Torkel Lodberg 1991   */
  5.  
  6. #include <stdio.h>
  7. #include <exec/types.h>
  8. #include <exec/memory.h>
  9. #include <intuition/intuition.h>
  10. #include <proto/intuition.h>
  11. #include <proto/graphics.h>
  12. #include <proto/exec.h>
  13. #include <fcntl.h>
  14. #include <ctype.h>
  15. #include <math.h>
  16.  
  17. #define NEW_FILETYPE_PHONE  6
  18.  
  19. struct pb_Data {        /*** V2.0-> file format ***/
  20.     UBYTE name[41];             /* Name of this board */
  21.     UBYTE phone[61];            /* The phonenumber(s) */
  22.     UBYTE comment[41];          /* A comment */
  23.     UBYTE pass_word[30];        /* Password for this board */
  24.     UBYTE script_file[33];      /* Script filename */
  25.     UBYTE config_file[33];      /* Config filename */
  26.     UBYTE macro_file[33];       /* Macro filename */
  27.     UBYTE char_set;        /* Char. set (0-12), 0 == first item in submenu etc. */
  28.     UBYTE baud;            /* Baud rate (0-12), 0 == first item in submenu etc. */
  29.     UBYTE data_length;        /* TRUE if seven data bits */
  30.     UBYTE parity;        /* Parity (0-4), 0 == first item in submenu etc. */
  31.     UBYTE stop_bits;        /* TRUE if two stop bits */
  32.     UBYTE duplex;        /* TRUE if half duplex */
  33.     UBYTE swap_del_bs;        /* TRUE if we should swap Del/BS */
  34.     UBYTE protocol;        /* Protocol (0-8), 0 == first item in submenu etc. */
  35.     long last_login;        /* Date/time stamp created with time() */
  36.     UBYTE arexx_file[33];       /* ARexx filename */
  37.     UBYTE future[25];           /* Reserved for future use, keep these zero'ed */
  38. };
  39.  
  40. static int      fd = NULL;    /* File handle */
  41.  
  42. UBYTE           wb_open;    /* Started from workbench? */
  43.  
  44. void
  45. cleanup(text)            /* Exit program cleanly */
  46.     char           *text;
  47. {
  48.     if (text)
  49.     printf("%s\n", text);
  50.     if (fd > 0)
  51.     close(fd);
  52.     if (wb_open)
  53.     Delay(100);
  54.     exit(0);
  55. }
  56.  
  57. void
  58. brk()
  59. {                /* Called by every CTRL-C / D keypress */
  60.     printf("*** BREAK\n");
  61.     cleanup(NULL);
  62. }
  63.  
  64. void
  65. main(argc, argv)        /* Main program */
  66.     int             argc;
  67.     char           *argv[];
  68. {
  69.     char            ch, answer[256], infile[256];
  70.     struct pb_Data  data;
  71.  
  72.     wb_open = !argc;
  73.  
  74.     if (onbreak(&brk))
  75.     cleanup(NULL);
  76.     chkabort();
  77.  
  78.     if (wb_open || argc > 2) {
  79.     printf("PbView for use with NComm V1.9 or later.\n"
  80.            "Public Domain by Torkel Lodberg 1991\n\n");
  81.     if (!wb_open) {
  82.         printf("   Usage: PbConvert [phonebook]\n\n");
  83.         cleanup(NULL);
  84.     }
  85.     }
  86.  
  87.     if (argc < 2)
  88.        strcpy(infile, "NComm:NComm.phone");
  89.     else
  90.        strcpy(infile, argv[1]);
  91.  
  92.     if (wb_open) {
  93.     printf("Enter name of phonebook file (Enter=NComm:NComm.phone): ");
  94.     gets(answer);
  95.     if (strlen(answer))
  96.         strcpy(infile, answer);
  97.         printf("\n");
  98.     }
  99.  
  100.     if ((fd = open(infile, O_RDONLY, NULL)) == -1 || read(fd, &ch, 1) != 1)
  101.        cleanup("Cannot open data-file");
  102.  
  103.     if (ch != NEW_FILETYPE_PHONE)
  104.     cleanup("Error reading NComm.phone: Illegal file type");
  105.  
  106.     while ((read(fd, (char *) &data, sizeof(struct pb_Data))) == sizeof(struct pb_Data)) {
  107.           printf("%-30s %s\n", data.name, data.phone);
  108.     }
  109.  
  110.     cleanup(NULL);
  111. }
  112.