home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / comm / misc / elcheapofax / faxcmd / rcs / faxsend.c,v < prev    next >
Text File  |  1993-12-21  |  5KB  |  281 lines

  1. head    1.4;
  2. access;
  3. symbols
  4.     OCT93:1.4;
  5. locks;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.4
  10. date    93.10.25.02.18.43;    author Rhialto;    state Exp;
  11. branches;
  12. next    1.3;
  13.  
  14. 1.3
  15. date    93.09.18.20.29.19;    author Rhialto;    state Exp;
  16. branches;
  17. next    1.2;
  18.  
  19. 1.2
  20. date    93.06.11.16.31.57;    author Rhialto;    state Exp;
  21. branches;
  22. next    1.1;
  23.  
  24. 1.1
  25. date    93.06.11.15.16.34;    author Rhialto;    state Exp;
  26. branches;
  27. next    ;
  28.  
  29.  
  30. desc
  31. @Send faxes to the modem
  32. @
  33.  
  34.  
  35. 1.4
  36. log
  37. @Make +FBOR flexible.
  38. @
  39. text
  40. @/* $Id: faxsend.c,v 1.3 1993/09/18 20:29:19 Rhialto Exp $
  41.  * $Log: faxsend.c,v $
  42.  * Revision 1.3  1993/09/18  20:29:19  Rhialto
  43.  * Call faxmodem_sync() explicitly.
  44.  *
  45.  * Revision 1.2  1993/06/11  16:31:57  Rhialto
  46.  * First real RCS checkin
  47.  *
  48.  */
  49. /*
  50.  * This file is part of El Cheapo Fax. All modifications relative to the
  51.  * base source are (C) Copyright 1993 by Olaf 'Rhialto' Seibert.
  52.  * All rights reserved. The GNU General Public License applies.
  53.  */
  54. /*
  55.   This file is part of the NetFax system.
  56.  
  57.   (c) Copyright 1989 by David M. Siegel.
  58.       All rights reserved.
  59.  
  60.     This program is free software; you can redistribute it and/or modify
  61.     it under the terms of the GNU General Public License as published by
  62.     the Free Software Foundation.
  63.  
  64.     This program is distributed in the hope that it will be useful,
  65.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  66.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  67.     GNU General Public License for more details.
  68.  
  69.     You should have received a copy of the GNU General Public License
  70.     along with this program; if not, write to the Free Software
  71.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  72. */
  73.  
  74. #include <stdio.h>
  75. #include <stdlib.h>
  76. #include <fcntl.h>
  77. #include <time.h>
  78.  
  79. #include "libfax.h"
  80.  
  81. int getopt(int, char **, char *);
  82. static int do_send(FaxModem *fmp, int fd, int page, int last_page);
  83.  
  84. static int verbose = FALSE;
  85. static FaxModem fm;
  86.  
  87. #define EXIT_ERROR        21
  88. #define EXIT_NO_FILE        22
  89. #define EXIT_OPEN_FAILED    23
  90. #define EXIT_CALL_FAILED    24
  91. #define EXIT_SEND_FAILED    25
  92. #define EXIT_FINISH_FAILED    26
  93.  
  94. static int do_send(fmp, fd, page, last_page)
  95.      FaxModem *fmp;
  96.      int fd;
  97.      int page;
  98.      int last_page;
  99. {
  100.     long start = time(0);
  101.  
  102.     if (faxmodem_send_page(fmp, fd, last_page, MAX_PAGE_RETRIES) < 0)
  103.       return (-1);
  104.  
  105.     if (verbose)
  106.       printf("page %d sent in %d seconds\n", page, time(0) - start);
  107.  
  108.     return (0);
  109. }
  110.  
  111. /*
  112.  * This function was introduced by Olaf 'Rhialto' Seibert.
  113.  */
  114. static void cleanup()
  115. {
  116.     faxmodem_close(&fm);
  117. }
  118.  
  119. main(argc, argv)
  120.      int argc;
  121.      char *argv[];
  122. {
  123.     int c;
  124.     extern char *optarg;
  125.     extern int optind;
  126.     int errflg = 0;
  127.  
  128.     char *fax_device = FAX_DEVICE;
  129.     char *phone;
  130.     long start;
  131.  
  132.     log_set_level(LOG_WARNING);
  133.  
  134.     while ((c = getopt(argc, argv, "b:l:vf:")) != -1)
  135.       switch (c) {
  136.     case 'b':
  137.       bor_value = atoi(optarg);
  138.       break;
  139.     case 'l':
  140.       log_set_level(atoi(optarg));
  141.       break;
  142.     case 'v':
  143.       verbose = TRUE;
  144.       break;
  145.     case 'f':
  146.       fax_device = optarg;
  147.       break;
  148.     case '?':
  149.       errflg++;
  150.       break;
  151.       }
  152.  
  153.     if (errflg || optind >= argc) {
  154.     fprintf(stderr,
  155. "Usage: %s [-f faxdevice] [-l loglevel] [-v] [-b bitorder] phone [files..]\n", argv[0]);
  156.     exit(EXIT_ERROR);
  157.     }
  158.  
  159.     phone = argv[optind++];
  160.  
  161.     if (optind < argc) {
  162.     int ind;
  163.     for (ind = optind; ind < argc; ind++) {
  164.         if (access(argv[ind], R_OK) < 0) {
  165.         fprintf(stderr, "can't access file: %s\n", argv[ind]);
  166.         exit(EXIT_NO_FILE);
  167.         }
  168.     }
  169.     }
  170.  
  171.     atexit(cleanup);
  172.     if (faxmodem_open(&fm, fax_device) < 0 ||
  173.     faxmodem_sync(&fm, 10) < 0) {
  174.     fprintf(stderr, "open of fax failed\n");
  175.     exit(EXIT_OPEN_FAILED);
  176.     }
  177.  
  178.     if (faxmodem_initiate_call(&fm, phone) < 0 || !FAX_CONNECTED(&fm)) {
  179.     fprintf(stderr, "call to %s failed\n", phone);
  180.     exit(EXIT_CALL_FAILED);
  181.     }
  182.  
  183.     start = time(0);
  184.  
  185.     if (verbose) {
  186.     printf("connected to %s\n", phone);
  187.     faxmodem_print_id_strings(&fm, stdout);
  188.     }
  189.  
  190.     if (optind < argc) {
  191.     int page = 1;
  192.     for (; optind < argc; optind++) {
  193.         int fd;
  194.         if ((fd = open(argv[optind], O_RDONLY)) < 0) {
  195.         fprintf(stderr, "can't access file: %s\n", argv[optind]);
  196.         exit(EXIT_NO_FILE);
  197.         }
  198.         if (do_send(&fm, fd, page++, optind+1 == argc) < 0) {
  199.         fprintf(stderr, "sending failed on: %s\n", argv[optind]);
  200.         exit(EXIT_SEND_FAILED);
  201.         }
  202.     }
  203.     } else
  204.       if (do_send(&fm, 0, 1, TRUE) < 0) {
  205.       fprintf(stderr, "sending failed stdin\n");
  206.       exit(EXIT_SEND_FAILED);
  207.       }
  208.  
  209.  
  210.     if (faxmodem_hangup(&fm) < 0) {
  211.     fprintf(stderr, "hangup failed\n");
  212.     exit(EXIT_FINISH_FAILED);
  213.     }
  214.  
  215.     if (verbose)
  216.       printf("total connect time was %d seconds\n", time(0) - start);
  217.  
  218.     if (faxmodem_close(&fm) < 0) {
  219.     fprintf(stderr, "close failed\n");
  220.     exit(EXIT_FINISH_FAILED);
  221.     }
  222.  
  223.     exit(0);
  224. }
  225. @
  226.  
  227.  
  228. 1.3
  229. log
  230. @Call faxmodem_sync() explicitly.
  231. @
  232. text
  233. @d1 1
  234. a1 1
  235. /* $Id: faxsend.c,v 1.2 1993/06/11 16:31:57 Rhialto Exp $
  236. d3 3
  237. a47 2
  238. #define MAX_TRIES  3
  239.  
  240. d63 1
  241. a63 1
  242.     if (faxmodem_send_page(fmp, fd, last_page, MAX_TRIES) < 0)
  243. d95 1
  244. a95 1
  245.     while ((c = getopt(argc, argv, "l:vf:")) != -1)
  246. d97 3
  247. d116 1
  248. a116 1
  249. "Usage: %s [-f faxdevice] [-l loglevel] [-v] phone [files..]\n", argv[0]);
  250. @
  251.  
  252.  
  253. 1.2
  254. log
  255. @First real RCS checkin
  256. @
  257. text
  258. @d1 5
  259. a5 2
  260. /* $Id$
  261.  * $Log$
  262. d129 2
  263. a130 1
  264.     if (faxmodem_open(&fm, fax_device) < 0) {
  265. @
  266.  
  267.  
  268. 1.1
  269. log
  270. @Initial revision
  271. @
  272. text
  273. @d1 3
  274. d89 1
  275. a89 1
  276.     /*log_set_level(LOG_WARNING);*/
  277. d108 2
  278. a109 1
  279.     fprintf(stderr, "usage: %s phone [files..]\n", argv[0]);
  280. @
  281.