home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / ispin / part02 < prev    next >
Encoding:
Text File  |  1992-02-01  |  56.7 KB  |  2,187 lines

  1. Newsgroups: comp.sources.unix
  2. From: sir-alan!ispin!lbartz@iuvax.cs.indiana.edu (Larry Bartz)
  3. Subject: v25i113: Indianapolis Standard Printer Interface for Networked printers, Part02/15
  4. Sender: sources-moderator@pa.dec.com
  5. Approved: vixie@pa.dec.com
  6.  
  7. Submitted-By: sir-alan!ispin!lbartz@iuvax.cs.indiana.edu (Larry Bartz)
  8. Posting-Number: Volume 25, Issue 113
  9. Archive-Name: ispin/part02
  10.  
  11. #! /bin/sh
  12. # This is a shell archive.  Remove anything before this line, then unpack
  13. # it by saving it into a file and typing "sh file".  To overwrite existing
  14. # files, type "sh file -c".  You can also feed this as standard input via
  15. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  16. # will see the following message at the end:
  17. #        "End of archive 2 (of 15)."
  18. # Contents:  ISPI/ispi.c ISPI/UUSTUFF.dr/SYS_III.dr/uustart.c
  19. #   ISPI/UUSTUFF.dr/SYS_V.dr/uustart.c
  20. # Wrapped by socrates@indy6 on Tue Jan 28 15:26:26 1992
  21. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  22. if test -f 'ISPI/ispi.c' -a "${1}" != "-c" ; then 
  23.   echo shar: Will not clobber existing file \"'ISPI/ispi.c'\"
  24. else
  25. echo shar: Extracting \"'ISPI/ispi.c'\" \(43525 characters\)
  26. sed "s/^X//" >'ISPI/ispi.c' <<'END_OF_FILE'
  27. X/****************************************************************************/
  28. X/*                                                                          */
  29. X/*  ISPI                                                                    */
  30. X/*                                                                          */
  31. X/*  Indianapolis Standard Printer Interface                                 */
  32. X/*                                                                          */
  33. X/*  - generates printer selection menu from table, serves as front-end      */
  34. X/*    for System V lp/lpsched or Zilog System III nq/dqueuer spoolers.      */
  35. X/*                                                                          */
  36. X/****************************************************************************/
  37. X/*                                                                          */
  38. X/*  Copyright (C) 1991                                                      */
  39. X/*  Kent Meurer                                                             */
  40. X/*  Internal Revenue Service                                                */
  41. X/*  Indianapolis District Office                                            */
  42. X/*                                                                          */
  43. X/*  This program is free software; you can redistribute it and/or modify    */
  44. X/*  it under the terms of the GNU General Public License as published by    */
  45. X/*  the Free Software Foundation, version 1.                                */
  46. X/*                                                                          */
  47. X/*  This program is distributed in the hope that it will be useful,         */
  48. X/*  but WITHOUT ANY WARRANTY; without even the implied warranty of          */
  49. X/*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           */
  50. X/*  GNU General Public License for more details.                            */
  51. X/*                                                                          */
  52. X/*  You should have received a copy of the GNU General Public License       */
  53. X/*  along with this program; if not, write to the Free Software             */
  54. X/*  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.               */
  55. X/*                                                                          */
  56. X/****************************************************************************/
  57. X/*
  58. X
  59. X *
  60. X  COMPILE
  61. X        Zilog System III Zeus Unix:         cc -o ispi ispi.c -s
  62. X        Zilog System V (Models 32 & 130):   cc -f -DSYSTEM_V -o ispi ispi.c -s
  63. X        Sequent System V Unix:              cc -DSEQUENT -o ispi ispi.c -s
  64. X        Other System V:                     cc -DSYSTEM_V -o ispi ispi.c -s
  65. X
  66. X             *
  67. X              If Supporting ISPIN's external printing, include -DEXTERN
  68. X              in the above compile lines.
  69. X
  70. X              If Supporting ISPI's file transfer capability, include -DXFER
  71. X              in the above compile lines. Also check value assigned to
  72. X              XFERCMD constant, below.
  73. X
  74. X              If Supporting UUCP printing, (88.  Print to Another System),
  75. X              include -DUUCP in the above compile lines.
  76. X
  77. X              Written by:             Kent Meurer   IRS, Indianapolis District
  78. X              modifications by:       Larry Bartz   IRS, Indianapolis District
  79. X              modifications by:       Kevin Fannin  IRS, Indianapolis District
  80. X
  81. X
  82. X                                                                              */
  83. X
  84. X#include <stdio.h>
  85. X#include <sys/utsname.h>
  86. X#include <signal.h>
  87. X#include <pwd.h>
  88. X
  89. Xstruct term_types
  90. X {
  91. X   char term[8];
  92. X   char on[8];
  93. X   char off[8];
  94. X };
  95. X
  96. Xstatic struct term_types terminals[] =  {
  97. X/* Use octal representations of unprintable chars for ON and OFF strings.     */
  98. X/* Terminate strings with \\c so echo does not send a newline. See echo(1).   */
  99. X/*        TERM    ON     OFF                                                  */
  100. X/*        ----    --     ---                                                  */
  101. X          {"v5", "\033*\\c", "\033?\\c"},    /* Visual 50/55/65               */
  102. X          {"v55", "\033*\\c", "\033?\\c"},   /* Visual 50/55/65               */
  103. X          {"v65", "\033*\\c", "\033?\\c"},   /* Visual 50/55/65               */
  104. X          {"d2", "\033[5i\\c", "\033[4i\\c"},/* TI/IBM PC's (VT100 Termcap)   */
  105. X          {"vt100", "\033[5i\\c", "\033[4i\\c"},  /*  PC's (VT100 Termcap)    */
  106. X          {"wy50", "\030\\c", "\024\\c"},      /* Wyse 50                       */
  107. X                                             /* add new terminal type(s) here */
  108. X          {"\0", "\0", "\0"}            };
  109. X
  110. X#define MAX_PRINTERS  28
  111. X#define TERM_ENV      "TERM"
  112. X#define CONFIG_ENV    "CONFIGDIR"
  113. X#define TRUE          1
  114. X#define FALSE         0
  115. X#define FLAG(x)       (x == '-')
  116. X#define NUM(x)        ((x >= '0') && (x <= '9'))
  117. X#define WS(x)         ((x == ' ') || (x == '\t'))
  118. X#define NL(x)         ((x == '\n') || (x == '\r'))
  119. X#define NP(x)         (x == 014)
  120. X#define ASCII(x)      (((x >= 040) && (x <= 0176)) || \
  121. X                        (x == 010) || (x == 011) || (x == 012))
  122. X
  123. X#ifdef  EXTERN
  124. X#  define EXTERN_QUEUE_NAME   "ext"
  125. X#endif
  126. X
  127. X#ifdef SEQUENT
  128. X#  define SYSTEM_V
  129. X#  define CLEAR               "/usr/ucb/clear"
  130. X#  ifdef UUCP
  131. X#    define UUX               "ucb uux"
  132. X#    define UUNAME            "ucb uuname"
  133. X#  endif
  134. X#else
  135. X#  define CLEAR               "clear"
  136. X#  ifdef UUCP
  137. X#    define UUX               "uux"
  138. X#    define UUNAME            "uuname"
  139. X#  endif
  140. X#endif
  141. X
  142. X#ifdef SYSTEM_V
  143. X#  define setjmpret(p)        setjmp(p)
  144. X#  define longjmpret(s, n)    longjmp(s, n)
  145. X#  define CONFIG_PATH         "/usr/spool/lp/ISPIN"
  146. X#  ifdef EXTERN
  147. X#    define RTAB_PATH         "/usr/spool/lp/ISPIN"
  148. X#  endif
  149. X#else
  150. X#  define setjmpret(p)        setret(p)
  151. X#  define longjmpret(s, n)    longret(s, n)
  152. X#  define CONFIG_PATH         "/usr/spool/queuer"
  153. X#  ifdef EXTERN
  154. X#    define RTAB_PATH         "/usr/spool/queuer/ISPIN"
  155. X#  endif
  156. X#endif
  157. X
  158. X/* file xfer stuff 12/11/90 LSB */
  159. X#ifdef XFER
  160. X
  161. X   /* command to be invoked to transfer the file to user's system */
  162. X
  163. X#  define XFERCMD             "/usr/local/bin/kermit -is"
  164. X
  165. X   /* An environmental variable will override the compiled-in value, */
  166. X   /* such as if certain (group of) user(s) would prefer to use [u,x,z]modem */
  167. X#  define XFER_ENV            "XFERCMD"
  168. X#endif
  169. X
  170. X
  171. Xtypedef int            ret_buf[10];
  172. Xtypedef unsigned int   index;
  173. Xtypedef unsigned short bool;
  174. X
  175. Xstruct device
  176. X {
  177. X   char q_name[15];
  178. X   char d_name[6];
  179. X   char comments[21];
  180. X };
  181. X
  182. XFILE              *fopen(), *config, *tty, *report;
  183. Xunsigned short    exit_status = 0, num_printers;
  184. Xint               num_choices, choice, c, copies = 1, fileargc, get_groupid(),
  185. X                  usergroupid, proc_id;
  186. Xchar              que_name[9], current_config[50], curr_system[10], printer[15],
  187. X                  clear_buff[256], file_buffer[BUFSIZ], prog_name[15], term[10],
  188. X                  *getenv(), *fileargv[100], *config_ptr, config_path[50];
  189. X#ifdef XFER
  190. Xchar              *xfer_ptr, xfer_cmd[50];
  191. Xvoid              xfer_it();
  192. X#endif
  193. Xstruct term_types *t_ptr;
  194. Xstruct device     devices[MAX_PRINTERS+1], *d_ptr;
  195. Xstruct utsname    *sys_name, tmp_struct;
  196. Xvoid              clear_scr(), ignore_line(), get_queue_descriptor(), view(), 
  197. X                  get_device_descriptor(), save_comments(), set_lps(), show(),
  198. X                  print_menu(), get_choice(), verify_choice(),
  199. X                  get_copies(), printjob(), delfunc(), sysdelfunc(), uname(),
  200. X                  check_group();
  201. Xbool              no_choice_has_been_made = TRUE,
  202. X                  remote_printer = FALSE, lp = FALSE, clear_set = FALSE,
  203. X                  setcom = FALSE, banner = FALSE, copy = FALSE, mail = FALSE,
  204. X                  all_printers = FALSE;
  205. Xret_buf           print, sys;
  206. X
  207. X
  208. X#ifdef UUCP
  209. X  unsigned short  num_systems = 0;
  210. X  static char     systems[32][9];
  211. X  void            get_system();
  212. X  bool            systems_set = FALSE;
  213. X#endif
  214. X
  215. X#ifdef EXTERN
  216. X  void            ignore_queue_name(), show_externs(), extdelfunc(),
  217. X                  load_externs();
  218. X  char            address[128];
  219. X  ret_buf         ext;
  220. X  bool            externs = FALSE;
  221. X#endif
  222. X
  223. X
  224. Xmain(argc, argv)
  225. X int  argc;
  226. X char *argv[];
  227. X {
  228. X  index  n = 1;
  229. X  bool   q_came_first = FALSE, buffer_not_loaded = TRUE;
  230. X
  231. X   if((tty = fopen((ttyname(0)),"w")) == NULL)
  232. X    {
  233. X      fprintf(stderr,"Not a tty\n");
  234. X      exit(5);
  235. X    }
  236. X
  237. X   signal(SIGQUIT, SIG_IGN);
  238. X   signal(SIGINT, SIG_IGN);
  239. X
  240. X   strcpy(prog_name, argv[0]);
  241. X
  242. X   /* Added support for defining config file location via ENVIRONMENT */
  243. X   /* variable named CONFIGDIR.                                       */
  244. X   /* 08/07/90   LSB                                                  */
  245. X   config_ptr = getenv(CONFIG_ENV);
  246. X   if(config_ptr ==  (char *)0)
  247. X   {
  248. X     sprintf(current_config,"%s/config", CONFIG_PATH);
  249. X     sprintf(config_path,"%s", CONFIG_PATH);
  250. X   }
  251. X   else
  252. X   {
  253. X     sprintf(current_config,"%s/config", config_path);
  254. X     /* Include alternative to revert to compiled-in path */
  255. X     /* if the environmental variable is ill-defined.     */
  256. X     if((config = fopen(current_config,"r")) == NULL)
  257. X     {
  258. X       sprintf(current_config,"%s/config", CONFIG_PATH);
  259. X       sprintf(config_path,"%s", CONFIG_PATH);
  260. X     }
  261. X     else
  262. X     {
  263. X       fclose(config);
  264. X     }
  265. X   }
  266. X
  267. X
  268. X   if((config = fopen(current_config,"r")) == NULL)
  269. X    {
  270. X        fprintf(stderr, "%s: Print Request Aborted - Unable to open %s\n",
  271. X                         prog_name, current_config);
  272. X        exit(7);
  273. X
  274. X    }
  275. X
  276. X
  277. X   /* Added support for defining file transfer command via ENVIRONMENT */
  278. X   /* variable named XFERCMD.                                          */
  279. X   /* 12/10/90   LSB                                                   */
  280. X#ifdef XFER
  281. X   xfer_ptr = getenv(XFER_ENV);
  282. X   if(xfer_ptr != (char *)0)
  283. X   {
  284. X     strcpy(xfer_cmd,xfer_ptr);
  285. X   }
  286. X   else
  287. X   {
  288. X     strcpy(xfer_cmd, XFERCMD);
  289. X   }
  290. X#endif
  291. X
  292. X
  293. X   usergroupid = get_groupid();
  294. X
  295. X   sys_name = &tmp_struct;
  296. X   uname(sys_name);
  297. X   strcpy(curr_system,sys_name->nodename);
  298. X
  299. X
  300. X   while(FLAG(argv[n][0]))
  301. X    {
  302. X      switch(argv[n][1])
  303. X       {
  304. X         case 'a':
  305. X         case 'A':
  306. X                   all_printers = TRUE;
  307. X                   break;
  308. X         case 's':
  309. X                   setcom = TRUE;
  310. X                   break;
  311. X         case 'B':
  312. X                   banner = TRUE;
  313. X                   break;
  314. X         case 'm':
  315. X                   mail = TRUE;
  316. X                   break;
  317. X         case 'c':
  318. X                   copy = TRUE;
  319. X                   break;
  320. X         case 't':
  321. X                   copies = atoi(argv[n+1]);
  322. X                   if(copies < 1)
  323. X                    copies = 1;
  324. X                   n++;
  325. X                   break;
  326. X         case 'd':
  327. X         case 'p':           /* ignore these nq flags and their args */
  328. X                   n++;
  329. X                   break;
  330. X         default:            /* ignore other flags we don't support  */
  331. X                   break;
  332. X       }
  333. X      n++;
  334. X    }
  335. X
  336. X   if((n == argc) && (! setcom))
  337. X    {
  338. X      fileargv[0] = &file_buffer[0];
  339. X      fileargc = 1;
  340. X      while(buffer_not_loaded)
  341. X       {
  342. X          n = 0;
  343. X          fprintf(tty,"\n\nEnter the name of the File(s) to be printed: ");
  344. X          fflush(tty);
  345. X
  346. X          file_buffer[n] = getc(stdin);
  347. X
  348. X          while(WS(file_buffer[n]))
  349. X            file_buffer[n] = getc(stdin);
  350. X
  351. X          while((! NL(file_buffer[n])) && (n < BUFSIZ))
  352. X           {
  353. X             n++;
  354. X             file_buffer[n] = getc(stdin);
  355. X             while(! NL(file_buffer[n]) &&
  356. X                  (! WS(file_buffer[n])) && (n < BUFSIZ))
  357. X              {
  358. X                n++;
  359. X                file_buffer[n] = getc(stdin);
  360. X              }
  361. X
  362. X             if(WS(file_buffer[n]))
  363. X              {
  364. X                file_buffer[n] = '\0';
  365. X                n++;
  366. X                file_buffer[n] = getc(stdin);
  367. X                while(WS(file_buffer[n]))
  368. X                  file_buffer[n] = getc(stdin);
  369. X                if(! NL(file_buffer[n]))
  370. X                 {
  371. X                   fileargv[fileargc] = &file_buffer[n];
  372. X                   fileargc++;
  373. X                 }
  374. X              }
  375. X             buffer_not_loaded = FALSE;
  376. X           }
  377. X          file_buffer[n] = '\0';
  378. X       }
  379. X
  380. X      if(n >= BUFSIZ)
  381. X       {
  382. X         fprintf(stderr,"%s: File list too long\n", prog_name);
  383. X         exit(3);
  384. X       }
  385. X    }
  386. X   else
  387. X    {
  388. X      fileargc = 0;
  389. X      for(n; n < argc; n++, fileargc++)
  390. X        fileargv[fileargc] = argv[n];
  391. X    }
  392. X
  393. X
  394. X   while(no_choice_has_been_made)
  395. X    {
  396. X      setjmpret(print);
  397. X      signal(SIGINT, delfunc);
  398. X      num_printers = 0;
  399. X      d_ptr = devices;
  400. X      while(((c = getc(config)) == ' ') || (c == '\t'));
  401. X      lp = FALSE;
  402. X
  403. X      while((c != EOF) && (num_printers < MAX_PRINTERS))
  404. X       {
  405. X         switch(c)
  406. X          {
  407. X            case '#':
  408. X              ignore_line();
  409. X              break;
  410. X            case 'Q':
  411. X              q_came_first = TRUE;
  412. X              get_queue_descriptor();
  413. X              break;
  414. X            case 'D':
  415. X              if(q_came_first)
  416. X               {
  417. X                 get_device_descriptor();
  418. X                 num_printers++;
  419. X               }
  420. X              else
  421. X               {
  422. X                 fprintf(stderr,
  423. X                   "Print Request Unsuccessful - %s: file garbled\n",
  424. X                   current_config);
  425. X                 exit(8);
  426. X               }
  427. X              break;
  428. X            case 'L':
  429. X            case 'l':
  430. X              if((((c = getc(config)) == 'P') || (c == 'p')) &&
  431. X                   (! q_came_first))
  432. X               {
  433. X                 lp = TRUE;
  434. X                 set_lps();
  435. X               }
  436. X              else
  437. X               {
  438. X                 fprintf(stderr,
  439. X                   "Print Request Unsuccessful - %s: file garbled\n",
  440. X                   current_config);
  441. X                 exit(8);
  442. X               }
  443. X              break;
  444. X            default:
  445. X              fprintf(stderr,
  446. X                "Print Request Unsuccessful - %s: file garbled\n",
  447. X                current_config);
  448. X              exit(8);
  449. X              break;
  450. X           }
  451. X          if(c != EOF)
  452. X            while(((c = getc(config)) == ' ') || (c == '\t'));
  453. X       }
  454. X
  455. X     q_came_first = FALSE;
  456. X     fclose(config);
  457. X     /* KDF 11/29/90 Following caused last printer to be blank on lp systems */
  458. X     /*              when menu was full.                                     */
  459. X     /* d_ptr->d_name[0] = d_ptr->q_name[0] = d_ptr->comments[0] = NULL;     */
  460. X     print_menu();
  461. X     get_choice();
  462. X     if(! no_choice_has_been_made)
  463. X      {
  464. X        if(! remote_printer)
  465. X         {
  466. X           if(lp)
  467. X             strcpy(printer,devices[choice-1].q_name);
  468. X           else
  469. X             sprintf(printer,"%s:%s", devices[choice-1].q_name,
  470. X                     devices[choice-1].d_name);
  471. X         }
  472. X        verify_choice();
  473. X      }
  474. X    }
  475. X
  476. X   printjob(fileargc, fileargv);
  477. X   fclose(tty);
  478. X   exit(exit_status);
  479. X }
  480. X
  481. X
  482. X/* Function added to get group id.    KDF 11/28/90 */
  483. Xint get_groupid()
  484. X {
  485. X   struct passwd *pwentry, *getpwuid();
  486. X
  487. X   pwentry = getpwuid(getuid());
  488. X   return(pwentry->pw_gid);
  489. X }
  490. X
  491. Xvoid verify_choice()
  492. X {
  493. X   signal(SIGINT, delfunc);
  494. X
  495. X   clear_scr();
  496. X   fprintf(tty, "\n\n\n\n\n\n\n\n\n                You have selected ");
  497. X
  498. X   if(remote_printer)
  499. X     fprintf(tty, "Slave Printing");
  500. X   else
  501. X
  502. X#  ifdef EXTERN
  503. X   if(externs)
  504. X    {
  505. X       fprintf(tty, "%s - %s", printer, devices[choice-1].comments);
  506. X       fprintf(tty, 
  507. X               "\n                                  @ address %s", address);
  508. X    }
  509. X   else
  510. X#  endif
  511. X
  512. X     fprintf(tty, "%s - %s", printer, devices[choice-1].comments);
  513. X
  514. X
  515. X   fprintf(tty, "\n\n                Is this correct (y/n) ? ");
  516. X   fflush(tty);
  517. X
  518. X   while(((c = getc(stdin)) == ' ') || (c == '\t'));
  519. X   if(c != '\n')
  520. X     while((getc(stdin)) != '\n');
  521. X
  522. X   if((c == 'Y') || (c == 'y'))
  523. X     return;
  524. X
  525. X#  ifdef EXTERN
  526. X     externs = FALSE;
  527. X#  endif
  528. X
  529. X   no_choice_has_been_made = TRUE;
  530. X   remote_printer  = FALSE;
  531. X
  532. X   if((config = fopen(current_config,"r")) == NULL)
  533. X    {
  534. X      fprintf(stderr, "%s: Print Request Aborted - Unable to open %s\n",
  535. X                       prog_name, current_config);
  536. X      exit(7);
  537. X    }
  538. X }
  539. X
  540. X
  541. X
  542. Xvoid clear_scr()
  543. X {
  544. X  FILE *clr;
  545. X  char *cptr;
  546. X
  547. X   if(! clear_set)
  548. X    {
  549. X      if((clr = popen(CLEAR, "r")) == NULL)
  550. X       {
  551. X         fprintf(stderr,"%s: bad status from system clear\n", prog_name);
  552. X         exit(6);
  553. X       }
  554. X      cptr = clear_buff;
  555. X      while(((c = getc(clr)) != EOF) && (cptr != &clear_buff[255]))
  556. X        *cptr++ = c;
  557. X
  558. X      *cptr = '\0';
  559. X
  560. X      clear_set = TRUE;
  561. X    }
  562. X
  563. X   fprintf(tty, "%s", clear_buff);
  564. X }
  565. X
  566. X
  567. X
  568. Xvoid ignore_line()
  569. X {
  570. X   while(((c = getc(config)) != '\n') && (c != EOF));
  571. X }
  572. X
  573. X
  574. X
  575. Xvoid get_queue_descriptor()
  576. X {
  577. X  index n = 0;
  578. X
  579. X   que_name[n] = getc(config);
  580. X   while((que_name[n] != ',') && (n < 9))
  581. X    {
  582. X      n++;
  583. X      que_name[n] = getc(config);
  584. X    }
  585. X   que_name[n] = '\0';
  586. X   ignore_line();
  587. X
  588. X#  ifdef EXTERN
  589. X     if((strcmp(que_name, EXTERN_QUEUE_NAME)) == 0)
  590. X       ignore_queue_name();
  591. X#  endif
  592. X }
  593. X
  594. X
  595. X
  596. X#ifdef EXTERN
  597. X
  598. Xvoid ignore_queue_name()
  599. X {
  600. X   while(((c = getc(config)) == ' ') || (c == '\t'));
  601. X   while((c != EOF) && (c != 'Q'))
  602. X    {
  603. X      ignore_line();
  604. X      while(((c = getc(config)) == ' ') || (c == '\t'));
  605. X    }
  606. X   ungetc(c,config);
  607. X }
  608. X
  609. X#endif
  610. X
  611. X
  612. X
  613. Xvoid get_device_descriptor()
  614. X {
  615. X  index n = 0;
  616. X
  617. X   strcpy(d_ptr->q_name,que_name);
  618. X   d_ptr->d_name[n] = getc(config);
  619. X   while((d_ptr->d_name[n] != ',') && (n < 6))
  620. X    {
  621. X      n++;
  622. X      d_ptr->d_name[n] = getc(config);
  623. X    }
  624. X   d_ptr->d_name[n] = '\0';
  625. X
  626. X   ignore_line();
  627. X   save_comments();
  628. X   d_ptr++;
  629. X }
  630. X
  631. X
  632. X
  633. Xvoid save_comments()
  634. X {
  635. X  index n = 0;
  636. X
  637. X   while(((c = getc(config)) == ' ') || (c == '\t'));
  638. X   if(c != '#')
  639. X    {
  640. X      while(n < 20)
  641. X        d_ptr->comments[n++] = ' ';
  642. X      d_ptr->comments[20] = '\0';
  643. X      ungetc(c,config);
  644. X      return;
  645. X    }
  646. X
  647. X   while(((d_ptr->comments[n] = getc(config)) == ' ') ||
  648. X          (d_ptr->comments[n] == '\t'));
  649. X   while((d_ptr->comments[n] != '\n') && (n < 20))
  650. X    {
  651. X      n++;
  652. X      c = getc(config);
  653. X      if(c != EOF)
  654. X       {
  655. X         if(c != '\t')
  656. X          d_ptr->comments[n] = c;
  657. X         else
  658. X          d_ptr->comments[n] = ' ';
  659. X       }
  660. X      else
  661. X        break;
  662. X    }
  663. X
  664. X   if((d_ptr->comments[n] != '\n') && (c != EOF))
  665. X     ignore_line();
  666. X
  667. X   while(n < 20)
  668. X    d_ptr->comments[n++] = ' ';
  669. X   d_ptr->comments[n] = '\0';
  670. X
  671. X   check_group(); /* Function to check optional printer group parameter */
  672. X }
  673. X
  674. X
  675. X/* Code added to read optional printer GROUP comment line. KDF 11/28/90 */
  676. X
  677. Xvoid check_group()
  678. X {
  679. X   int n, printergroup; 
  680. X   char holdnum[10];
  681. X
  682. X   while(((c = getc(config)) == ' ') || (c == '\t'));
  683. X   if (c != '#')
  684. X    {
  685. X      ungetc(c,config);
  686. X      return;
  687. X    }
  688. X
  689. X   while(((c = getc(config)) == ' ') || (c == '\t'));
  690. X
  691. X   if ( (toupper(c)) != 'G' || (toupper(getc(config))) != 'R' || 
  692. X        (toupper(getc(config))) != 'O' || (toupper(getc(config))) != 'U' || 
  693. X        (toupper(getc(config))) != 'P' || 
  694. X        ((c = (getc(config))) != ' ' && c != '\t')  )
  695. X     {
  696. X       ungetc(c,config);
  697. X       ignore_line();
  698. X       return;
  699. X     }
  700. X
  701. X   while(((c = getc(config)) == ' ') || (c == '\t'));
  702. X
  703. X   if ((toupper(c)) == 'A') /* all groups specified */
  704. X    {
  705. X      ignore_line();
  706. X      return;
  707. X    }
  708. X
  709. X  n = 0;
  710. X  while (c != '\n' && c != EOF)
  711. X    {
  712. X      if (c == ' ' || c == '\t')
  713. X        {
  714. X          holdnum[n] = '\0';
  715. X          printergroup = atoi(holdnum);
  716. X          if (printergroup == usergroupid)
  717. X            {
  718. X              ignore_line();
  719. X              return;
  720. X            }
  721. X          while(((c = getc(config)) == ' ') || (c == '\t'));
  722. X          n = 0;
  723. X        }
  724. X      else
  725. X        {
  726. X          holdnum[n] = c;
  727. X          n++;
  728. X          c = getc(config);
  729. X        }
  730. X    }
  731. X
  732. X  if (n > 0)
  733. X    {
  734. X      holdnum[n] = '\0';
  735. X      printergroup = atoi(holdnum);
  736. X      if (printergroup == usergroupid)
  737. X        return;
  738. X    }
  739. X
  740. X  /* if ispi called with -a flag, list all printers regardless of groups
  741. X     that are specified in config file */
  742. X  if (all_printers)
  743. X    return;
  744. X
  745. X  /* if didn't find users group listed, then remove this printer from list */
  746. X  d_ptr--;
  747. X  num_printers--;
  748. X
  749. X }
  750. X
  751. X
  752. Xvoid set_lps()
  753. X {
  754. X  index n = 0;
  755. X
  756. X   ignore_line();
  757. X   num_printers = 0;
  758. X
  759. X   while((c != EOF) && (num_printers < MAX_PRINTERS))
  760. X    {
  761. X      d_ptr->d_name[0] = '\0';
  762. X
  763. X      while((c = getc(config)) == '#')
  764. X        ignore_line();
  765. X
  766. X      while((WS(c)) || (NL(c)))
  767. X        c = getc(config);
  768. X
  769. X      while((! WS(c)) && (! NL(c)) && (c != EOF) && (n < 14))
  770. X       {
  771. X         d_ptr->q_name[n++] = c;
  772. X         c = getc(config);
  773. X       }
  774. X      if(n > 0)
  775. X        num_printers++;
  776. X      d_ptr->q_name[n++] = '\0';
  777. X
  778. X      while((! NL(c)) && (c != EOF))
  779. X         c = getc(config);
  780. X
  781. X      if(c == EOF)
  782. X        ungetc(c,config);
  783. X      save_comments();
  784. X
  785. X      n = 0;
  786. X      if(num_printers < MAX_PRINTERS)
  787. X        d_ptr++;
  788. X     }
  789. X }
  790. X
  791. X
  792. X
  793. Xvoid print_menu()
  794. X {
  795. X  int   len;
  796. X  index n;
  797. X  char  fprinter[15], fprinter2[15];
  798. X
  799. X   num_choices = 1;
  800. X   clear_scr();
  801. X   fprintf(tty,"\n                      ");
  802. X   fprintf(tty,"%s Printer Selection Menu\n", curr_system);
  803. X   fprintf(tty,"                      ");
  804. X   for(len = 0; len < strlen(curr_system); len++)
  805. X     fprintf(tty,"-");
  806. X   fprintf(tty," ------- --------- ----\n");
  807. X   if(num_printers < 19)
  808. X    fprintf(tty, "\n");
  809. X
  810. X
  811. X   if(num_printers < 10)
  812. X    {
  813. X      d_ptr = devices;
  814. X      /* Changed while statement KDF 11/29/90 */
  815. X      /* while(d_ptr->q_name[0] != NULL) */
  816. X      while(num_choices <= num_printers)
  817. X       {
  818. X        if(lp)
  819. X           fprintf(tty,"                     %2d.  %s  %s", num_choices,
  820. X                        d_ptr->comments, d_ptr->q_name);
  821. X        else
  822. X         {
  823. X           sprintf(fprinter, "%s:%s", d_ptr->q_name, d_ptr->d_name);
  824. X           fprintf(tty,"                     %2d.  %s  %s", num_choices,
  825. X                        d_ptr->comments, fprinter);
  826. X         }
  827. X
  828. X        for(len=(strlen(d_ptr->q_name)+strlen(d_ptr->d_name)); len <= 14; len++)
  829. X          fprintf(tty," ");
  830. X
  831. X        fprintf(tty,"\n");
  832. X        num_choices++;
  833. X        d_ptr++;
  834. X       }
  835. X
  836. X    }
  837. X   else
  838. X    {
  839. X      num_choices = num_printers + 1;
  840. X
  841. X      if((num_printers + 1) % 2)
  842. X       {
  843. X        for(n = 0; n < (num_printers/2); n++)
  844. X          if(lp)
  845. X            fprintf(tty,"%2d. %.20s %-14.14s %2d. %.20s %-14.14s\n", n+1,
  846. X                devices[n].comments, devices[n].q_name, n+((num_printers/2)+1),
  847. X                devices[n+(num_printers/2)].comments,
  848. X                devices[n+(num_printers/2)].q_name);
  849. X          else
  850. X           {
  851. X             sprintf(fprinter, "%s:%s", devices[n].q_name, devices[n].d_name);
  852. X             sprintf(fprinter2, "%s:%s", devices[n+(num_printers/2)].q_name,
  853. X                                      devices[n+(num_printers/2)].d_name);
  854. X
  855. X             fprintf(tty,"%2d. %.20s %-15.14s%2d. %.20s %s\n",
  856. X                 n+1, devices[n].comments, fprinter, n+((num_printers/2)+1),
  857. X                 devices[n+(num_printers/2)].comments, fprinter2);
  858. X           }
  859. X       }
  860. X      else
  861. X       {
  862. X        for(n = 0; n < (num_printers/2); n++)
  863. X          if(lp)
  864. X             fprintf(tty,"%2d. %.20s %-14.14s %2d. %.20s %-14.14s\n",
  865. X                 n+1, devices[n].comments, devices[n].q_name,
  866. X                 n+((num_printers/2)+2), devices[n+(num_printers/2)+1].comments,
  867. X                 devices[n+(num_printers/2)+1].q_name);
  868. X          else
  869. X           {
  870. X              sprintf(fprinter, "%s:%s", devices[n].q_name, devices[n].d_name);
  871. X              sprintf(fprinter2, "%s:%s", devices[n+(num_printers/2)+1].q_name,
  872. X                                      devices[n+(num_printers/2)+1].d_name);
  873. X              fprintf(tty,"%2d. %.20s %-15.14s%2d. %.20s %s\n",
  874. X                  n+1, devices[n].comments, fprinter, n+((num_printers/2)+2),
  875. X                  devices[n+(num_printers/2)+1].comments, fprinter2);
  876. X           }
  877. X
  878. X          if(lp)
  879. X              fprintf(tty,"%2d. %.20s %-14.14s\n",
  880. X                  n+1, devices[n].comments, devices[n].q_name);
  881. X          else
  882. X           {
  883. X              sprintf(fprinter, "%s:%s", devices[n].q_name, devices[n].d_name);
  884. X              fprintf(tty,"%2d. %.20s %-15.14s\n",
  885. X                  n+1, devices[n].comments, fprinter);
  886. X           }
  887. X
  888. X       }
  889. X    }
  890. X
  891. X   fprintf(tty,"\n");
  892. X
  893. X   if((strcmp(curr_system,sys_name->nodename)) == 0)
  894. X    {
  895. X#     ifdef XFER
  896. X      if(! setcom)
  897. X        fprintf(tty,"                     33.  Download File\n");
  898. X#     endif
  899. X#     ifdef EXTERN
  900. X        fprintf(tty,"                     44.  External Printers\n");
  901. X#     endif
  902. X      fprintf(tty,"                     55.  Slave Printer\n");
  903. X    }
  904. X   if(! setcom)
  905. X      fprintf(tty,"                     66.  View File on Terminal\n");
  906. X   fprintf(tty,
  907. X         "                     77.  Change Number of Copies - Currently %d\n",
  908. X                    copies);
  909. X#  ifdef UUCP
  910. X      fprintf(tty,"                     88.  Print File on Another System\n");
  911. X#  endif
  912. X   fprintf(tty,"                     99.  Abort Without Printing\n");
  913. X   fprintf(tty,"\n");
  914. X   if(num_printers < 19)
  915. X      fprintf(tty,"\n");
  916. X   fflush(tty);
  917. X }
  918. X
  919. X
  920. X
  921. Xvoid get_choice()
  922. X {
  923. X  index n = 0;
  924. X  char  char_choice[20];
  925. X
  926. X   while(1)
  927. X    {
  928. X      fprintf(tty,"                                 ");
  929. X      fprintf(tty,"Enter your choice: ");
  930. X      fflush(tty);
  931. X
  932. X      while(((char_choice[n] = getc(stdin)) == ' ') ||
  933. X             (char_choice[n] == '\t'));
  934. X
  935. X      if(! NL(char_choice[n]))
  936. X        n++;
  937. X
  938. X      if NUM(char_choice[n-1])
  939. X       {
  940. X         char_choice[n] = getc(stdin);
  941. X         while((NUM(char_choice[n])) && (n < 19))
  942. X          {
  943. X            n++;
  944. X            char_choice[n] = getc(stdin);
  945. X          }
  946. X       }
  947. X
  948. X      while(WS(char_choice[n]))
  949. X          char_choice[n] = getc(stdin);
  950. X
  951. X      if(! NL(char_choice[n]))
  952. X       {
  953. X          while(((c = getc(stdin)) != '\n') && (c != '\r'));
  954. X          n = 0;
  955. X       }
  956. X
  957. X      char_choice[n] = '\0';
  958. X
  959. X      choice = atoi(char_choice);
  960. X
  961. X      if((choice == 66) && (! setcom))
  962. X       {
  963. X         view(fileargc, fileargv);
  964. X         return;
  965. X       }
  966. X#ifdef XFER
  967. X      if((choice == 33) && (! setcom))
  968. X       {
  969. X         xfer_it(fileargc, fileargv);
  970. X         return;
  971. X       }
  972. X#endif
  973. X      else if(choice == 77)
  974. X       {
  975. X         get_copies();
  976. X         return;
  977. X       }
  978. X      else if(choice == 88)
  979. X       {
  980. X#        ifdef UUCP
  981. X           get_system();
  982. X           signal(SIGINT, delfunc);
  983. X           return;
  984. X#        else
  985. X           choice = 0;
  986. X#        endif
  987. X       }
  988. X      else if(choice == 99)
  989. X       {
  990. X         fprintf(tty,"\n                          Print Request Aborted\n");
  991. X         fclose(tty);
  992. X         if(setcom)
  993. X           fprintf(stdout,"abort");
  994. X         exit(1);
  995. X       }
  996. X      else if(choice == 44)
  997. X       {
  998. X#        ifdef EXTERN
  999. X           if((strcmp(curr_system,sys_name->nodename)) == 0)
  1000. X            {
  1001. X               show_externs();
  1002. X               break;
  1003. X            }
  1004. X           else
  1005. X             choice = 0;
  1006. X#        else
  1007. X           choice = 0;
  1008. X#        endif
  1009. X       }
  1010. X      else if(choice == 55)
  1011. X       {
  1012. X         if((strcmp(curr_system,sys_name->nodename)) == 0)
  1013. X          {
  1014. X            strcpy(term,(getenv(TERM_ENV)));
  1015. X            t_ptr = terminals;
  1016. X            while(((strcmp(term,t_ptr->term)) != 0) && (t_ptr->term[0] != '\0'))
  1017. X              t_ptr++;
  1018. X            if(t_ptr->term[0] == '\0')
  1019. X             {
  1020. X               fprintf(tty,"\nSlave Printing Denied: Unknown Terminal Type\n");
  1021. X               fflush(tty);
  1022. X               sleep(4);
  1023. X             }
  1024. X            else
  1025. X             {
  1026. X               remote_printer = TRUE;
  1027. X               no_choice_has_been_made = FALSE;
  1028. X               break;
  1029. X             }
  1030. X          }
  1031. X         else
  1032. X           choice = 0;
  1033. X       }
  1034. X
  1035. X      if((choice > 0) && (choice < num_choices))
  1036. X       {
  1037. X         no_choice_has_been_made = FALSE;
  1038. X         break;
  1039. X       }
  1040. X
  1041. X      fprintf(tty,"\n                              INVALID CHOICE");
  1042. X      fflush(tty);
  1043. X      sleep(2);
  1044. X
  1045. X      print_menu();
  1046. X      n = 0;
  1047. X    }
  1048. X }
  1049. X
  1050. X
  1051. X
  1052. X#ifdef EXTERN
  1053. X
  1054. Xvoid show_externs()
  1055. X {
  1056. X  char rtab[80];
  1057. X  index n;
  1058. X
  1059. X
  1060. X   setjmpret(ext);
  1061. X   signal(SIGINT, extdelfunc);
  1062. X
  1063. X   sprintf(rtab, "%s/rtab", RTAB_PATH);
  1064. X   fclose(config);
  1065. X   if((config = fopen(rtab,"r")) == NULL)
  1066. X    {
  1067. X      fprintf(tty,"\nExternal Printing Denied: Unable to open %s\n", rtab);
  1068. X      fflush(tty);
  1069. X      sleep(4);
  1070. X      if((config = fopen(current_config,"r")) == NULL)
  1071. X       {
  1072. X         fprintf(stderr, "%s: Print Request Aborted - Unable to open %s\n",
  1073. X                          prog_name, current_config);
  1074. X         exit(7);
  1075. X       }
  1076. X      return;
  1077. X    }
  1078. X   clear_scr();
  1079. X   load_externs();
  1080. X
  1081. X   strcpy(curr_system, "External");
  1082. X
  1083. X   no_choice_has_been_made = TRUE;
  1084. X   choice = 0;
  1085. X# ifdef UUCP
  1086. X   while((choice != 88) && (choice != 99) && (no_choice_has_been_made))
  1087. X# else
  1088. X   while((choice != 99) && (no_choice_has_been_made))
  1089. X# endif
  1090. X    {
  1091. X      print_menu();
  1092. X      get_choice();
  1093. X    }
  1094. X   if(! no_choice_has_been_made)
  1095. X    {
  1096. X      fprintf(tty, "\n\n                     Enter Address: ");
  1097. X      fflush(tty);
  1098. X      n = 0;
  1099. X      while(((address[n++] = getc(stdin)) != '\n') && (n < 127));
  1100. X      if(address[--n] != '\n')
  1101. X        while((getc(stdin)) != '\n');
  1102. X      address[n] = '\0';
  1103. X      externs = TRUE;
  1104. X      strcpy(curr_system,sys_name->nodename);
  1105. X    }
  1106. X }
  1107. X
  1108. X
  1109. X
  1110. Xvoid load_externs()
  1111. X {
  1112. X  char  ext_name[15];
  1113. X  index n;
  1114. X  bool  found_slash = FALSE;
  1115. X
  1116. X   d_ptr = devices;
  1117. X   num_printers = 0;
  1118. X
  1119. X   while(((c = getc(config)) == ' ') || (c == '\t'));
  1120. X   while(c != EOF)
  1121. X    {
  1122. X      if(c == '#')
  1123. X        ignore_line();
  1124. X      else
  1125. X       {
  1126. X         ext_name[0] = c;
  1127. X         n = 1;
  1128. X         while(((ext_name[n++] = getc(config)) != ';') && (n < 14));
  1129. X         ext_name[--n] = '\0';
  1130. X
  1131. X         while(((c = getc(config)) != '\n') && (c != EOF))
  1132. X          {
  1133. X            if(found_slash)
  1134. X             {
  1135. X               if(c == 'U')
  1136. X               {
  1137. X                 if(lp)
  1138. X                   strcpy(d_ptr->q_name, ext_name);
  1139. X                 else
  1140. X                  {
  1141. X                    strcpy(d_ptr->d_name, ext_name);
  1142. X                    strcpy(d_ptr->q_name, EXTERN_QUEUE_NAME);
  1143. X                  }
  1144. X                 ignore_line();
  1145. X                 save_comments();
  1146. X                 num_printers++;
  1147. X                 d_ptr++;
  1148. X                 found_slash = FALSE;
  1149. X                 break;
  1150. X               }
  1151. X              else
  1152. X               if(c != '\\')
  1153. X                 found_slash = FALSE;
  1154. X             }
  1155. X            else
  1156. X              if(c == '\\')
  1157. X               found_slash = TRUE;
  1158. X          }
  1159. X       }
  1160. X      if(c != EOF) /*&& ((c == ' ') || (c == '\t')))*/
  1161. X        while(((c = getc(config)) == ' ') || (c == '\t'));
  1162. X    }
  1163. X   d_ptr->q_name[0] = d_ptr->d_name[0] = '\0';
  1164. X }
  1165. X
  1166. X#endif
  1167. X
  1168. X
  1169. X
  1170. X#ifdef UUCP
  1171. X
  1172. Xvoid get_system()
  1173. X {
  1174. X  char  char_choice[6], command[20];
  1175. X  int   sys_choice;
  1176. X  short n;
  1177. X  bool  system_not_chosen = TRUE;
  1178. X  FILE  *uudata;
  1179. X
  1180. X   setjmpret(sys);
  1181. X   signal(SIGINT, sysdelfunc);
  1182. X
  1183. X   if(! systems_set)
  1184. X    {
  1185. X      sprintf(command, "%s | sort", UUNAME);
  1186. X
  1187. X      if((uudata = popen(command, "r")) == NULL)
  1188. X       {
  1189. X         fprintf(stderr,"%s: bad status from uuname\n", prog_name);
  1190. X         exit(6);
  1191. X       }
  1192. X
  1193. X      while((c = getc(uudata)) != EOF)
  1194. X       {
  1195. X         n = 0;
  1196. X         while(c != '\n')
  1197. X          {
  1198. X            systems[num_systems][n] = c;
  1199. X            n++;
  1200. X            c = getc(uudata);
  1201. X          }
  1202. X         systems[num_systems][n] = '\0';
  1203. X
  1204. X         sprintf(curr_system,"%s", systems[num_systems]);
  1205. X         sprintf(current_config,"%s/config%s", config_path, curr_system);
  1206. X
  1207. X         if((config = fopen(current_config,"r")) != NULL)
  1208. X          {
  1209. X            fclose(config);
  1210. X            num_systems++;
  1211. X          }
  1212. X
  1213. X         if(num_systems > 31)
  1214. X          break;
  1215. X       }
  1216. X      systems_set = TRUE;
  1217. X   }
  1218. X
  1219. X
  1220. X   while(system_not_chosen)
  1221. X    {
  1222. X      clear_scr();
  1223. X      fprintf(tty,"\n\n");
  1224. X      fprintf(tty,"                            System Selection Menu\n");
  1225. X      fprintf(tty,"                            ------ --------- ----\n");
  1226. X
  1227. X      if(num_systems < 9)
  1228. X       {
  1229. X          for(n = 0; n < num_systems; n++)
  1230. X            fprintf(tty, "\n                     %2d.  %s", n+1, systems[n]);
  1231. X          fprintf(tty, "\n                      ");
  1232. X          fprintf(tty,"%d.  Return to Local System Menu (%s)\n\n",num_systems+1,
  1233. X                     sys_name->nodename );
  1234. X       }
  1235. X      else
  1236. X       {
  1237. X         if((num_systems + 1) % 2)
  1238. X          {
  1239. X           for(n = 0; n < (num_systems/2); n++)
  1240. X             fprintf(tty,
  1241. X                "\n                   %2d.  %-9s           %2d.  %-9s", n+1,
  1242. X                systems[n], n+((num_systems/2)+1), systems[n+(num_systems/2)]);
  1243. X          }
  1244. X         else
  1245. X          {
  1246. X           for(n = 0; n < (num_systems/2); n++)
  1247. X            fprintf(tty, "\n                   %2d.  %-9s           %2d.  %-9s",
  1248. X                n+1, systems[n], n+((num_systems/2)+2),
  1249. X                systems[n+(num_systems/2)+1]);
  1250. X            fprintf(tty, "\n                   %2d.  %-9s",
  1251. X                ((num_systems/2)+1), systems[(num_systems/2)]);
  1252. X          }
  1253. X        fprintf(tty, "\n\n                   ");
  1254. X        fprintf(tty,"%d.  Return to Local System Menu (%s)\n\n",num_systems+1,
  1255. X            sys_name->nodename );
  1256. X      }
  1257. X
  1258. X
  1259. X      fprintf(tty,"\n                                        ");
  1260. X      fprintf(tty,"Enter your choice: ");
  1261. X      fflush(tty);
  1262. X
  1263. X      n = 0;
  1264. X      while(((char_choice[n] = getc(stdin)) == ' ') ||
  1265. X             (char_choice[n] == '\t'));
  1266. X
  1267. X      if(! NL(char_choice[n]))
  1268. X        n++;
  1269. X
  1270. X      if NUM(char_choice[n-1])
  1271. X       {
  1272. X         char_choice[n] = getc(stdin);
  1273. X         while((NUM(char_choice[n])) && (n < 19))
  1274. X          {
  1275. X            n++;
  1276. X            char_choice[n] = getc(stdin);
  1277. X          }
  1278. X       }
  1279. X
  1280. X      while(WS(char_choice[n]))
  1281. X        char_choice[n] = getc(stdin);
  1282. X
  1283. X      if(! NL(char_choice[n]))
  1284. X       {
  1285. X         while(((c = getc(stdin)) != '\n') && (c != '\r'));
  1286. X         n = 0;
  1287. X       }
  1288. X
  1289. X      char_choice[n] = '\0';
  1290. X      sys_choice = atoi(char_choice);
  1291. X
  1292. X      if((sys_choice > 0) && (sys_choice <= (num_systems+1)))
  1293. X        system_not_chosen = FALSE;
  1294. X      else
  1295. X       {
  1296. X         fprintf(tty,"\n                              INVALID CHOICE");
  1297. X         fflush(tty);
  1298. X         sleep(2);
  1299. X       }
  1300. X
  1301. X    }
  1302. X
  1303. X   if(sys_choice == (num_systems+1))
  1304. X    {
  1305. X      strcpy(curr_system,sys_name->nodename);
  1306. X      sprintf(current_config,"%s/config" ,config_path);
  1307. X    }
  1308. X  else
  1309. X    {
  1310. X      sprintf(curr_system,"%s", systems[sys_choice-1]);
  1311. X      sprintf(current_config,"%s/config%s", config_path, curr_system);
  1312. X    }
  1313. X
  1314. X   if((config = fopen(current_config,"r")) == NULL)
  1315. X    {
  1316. X      fprintf(stderr, "%s: Print Request Aborted - Unable to open %s\n",
  1317. X                       prog_name, current_config);
  1318. X      exit(7);
  1319. X    }
  1320. X }
  1321. X
  1322. X#endif
  1323. X
  1324. X
  1325. X
  1326. Xvoid view(vargc, vargv)
  1327. X int  vargc;
  1328. X char *vargv[];
  1329. X {
  1330. X  index n;
  1331. X
  1332. X   fclose(config);
  1333. X
  1334. X   for(n = 0; n < vargc; n++)
  1335. X    {
  1336. X      if((report = fopen(vargv[n],"r")) == NULL)
  1337. X       {
  1338. X         clear_scr();
  1339. X         fprintf(tty,"\n\n\n%s: Cannot open %s\n\n\n", prog_name, vargv[n]);
  1340. X       }
  1341. X      else
  1342. X       {
  1343. X         clear_scr();
  1344. X         fprintf(tty, "\n\n\n\n\nNext File: %s", vargv[n]);
  1345. X         fprintf(tty, "\n\n\n\n<RETURN> to Continue - <DEL> to Abort ");
  1346. X         fflush(tty);
  1347. X         while((getc(stdin)) != '\n');
  1348. X         show();
  1349. X         fclose(report);
  1350. X       }
  1351. X      fprintf(tty, "<RETURN> to Continue ");
  1352. X      fflush(tty);
  1353. X      while((getc(stdin)) != '\n');
  1354. X    }
  1355. X   if((config = fopen(current_config,"r")) == NULL)
  1356. X    {
  1357. X      fprintf(stderr, "%s: Print Request Aborted - Unable to open %s\n",
  1358. X                       prog_name, current_config);
  1359. X      exit(7);
  1360. X    }
  1361. X
  1362. X }
  1363. X
  1364. X
  1365. X
  1366. Xvoid show()
  1367. X {
  1368. X   short columns = 0, rows = 0;
  1369. X
  1370. X    clear_scr();
  1371. X
  1372. X    while((c = getc(report)) != EOF)
  1373. X     {
  1374. X       if(ASCII(c))
  1375. X        {
  1376. X          if(rows >= 23)
  1377. X           {
  1378. X             fprintf(tty, "<RETURN> to Continue - <DEL> to Abort ");
  1379. X             fflush(tty);
  1380. X             while((getc(stdin)) != '\n');
  1381. X             rows = columns = 0;
  1382. X           }
  1383. X          fputc(c, tty);
  1384. X          columns++;
  1385. X          if((c == '\r') || (c == '\n') || (columns >= 80))
  1386. X           {
  1387. X             columns = 0;
  1388. X             rows++;
  1389. X           }
  1390. X        }
  1391. X       else
  1392. X        if(NP(c))
  1393. X         do
  1394. X          {
  1395. X            fputc('\n', tty);
  1396. X            rows++;
  1397. X          } while(rows < 23);
  1398. X     }
  1399. X
  1400. X    while(rows < 23)
  1401. X     {
  1402. X       fputc('\n', tty);
  1403. X       rows++;
  1404. X     }
  1405. X }
  1406. X
  1407. X
  1408. X
  1409. Xvoid get_copies()
  1410. X {
  1411. X  char  cnum[3];
  1412. X  bool  get_number = TRUE;
  1413. X  short tmp_copies;
  1414. X
  1415. X  while(get_number)
  1416. X   {
  1417. X     clear_scr();
  1418. X     fprintf(tty, "\n\n\nEnter Number of Copies (1-10 default = 1) : ");
  1419. X     fflush(tty);
  1420. X
  1421. X     while(((cnum[0] = getc(stdin)) == ' ') || (cnum[0] == '\t'));
  1422. X
  1423. X     if(cnum[0] == '\n')
  1424. X      {
  1425. X        copies = 1;
  1426. X        break;
  1427. X      }
  1428. X
  1429. X     if(! NUM(cnum[0]))
  1430. X      {
  1431. X        while((cnum[0] = getc(stdin)) != '\n');
  1432. X        fprintf(tty, "\n\n\07Bad Number - Please Re-enter");
  1433. X        fflush(tty);
  1434. X        sleep(2);
  1435. X        continue;
  1436. X      }
  1437. X
  1438. X     cnum[1] = getc(stdin);
  1439. X     if(cnum[1] == '\n')
  1440. X       cnum[1] = '\0';
  1441. X     else
  1442. X      {
  1443. X       if(! NUM(cnum[1]))
  1444. X        {
  1445. X          while((cnum[0] = getc(stdin)) != '\n');
  1446. X          fprintf(tty, "\n\n\07Bad Number - Please Re-enter");
  1447. X          fflush(tty);
  1448. X          sleep(2);
  1449. X          continue;
  1450. X        }
  1451. X
  1452. X       cnum[2] = getc(stdin);
  1453. X       if(cnum[2] != '\n')
  1454. X        {
  1455. X          while((cnum[0] = getc(stdin)) != '\n');
  1456. X          fprintf(tty, "\n\n\07Bad Number - Please Re-enter");
  1457. X          fflush(tty);
  1458. X          sleep(2);
  1459. X          continue;
  1460. X        }
  1461. X       cnum[2] = '\0';
  1462. X
  1463. X      }
  1464. X
  1465. X   tmp_copies = atoi(cnum);
  1466. X   if(tmp_copies > 10)
  1467. X    {
  1468. X      fprintf(tty, "\n\n10 Copy Maximum");
  1469. X      fflush(tty);
  1470. X      sleep(2);
  1471. X      continue;
  1472. X    }
  1473. X   else
  1474. X   if(tmp_copies < 1)
  1475. X    {
  1476. X      fprintf(tty, "\n\n1 Copy Minimum");
  1477. X      fflush(tty);
  1478. X      sleep(2);
  1479. X      continue;
  1480. X    }
  1481. X   else
  1482. X    get_number = FALSE;
  1483. X
  1484. X   copies = tmp_copies;
  1485. X
  1486. X  }
  1487. X
  1488. X   if((config = fopen(current_config,"r")) == NULL)
  1489. X    {
  1490. X      fprintf(stderr, "%s: Print Request Aborted - Unable to open %s\n",
  1491. X                       prog_name, current_config);
  1492. X      exit(7);
  1493. X    }
  1494. X }
  1495. X
  1496. X
  1497. X
  1498. Xvoid delfunc()
  1499. X {
  1500. X   signal(SIGQUIT, SIG_IGN);
  1501. X   signal(SIGINT, delfunc);
  1502. X
  1503. X   fclose(config);
  1504. X   if((config = fopen(current_config, "r")) == NULL)
  1505. X    {
  1506. X      fprintf(stderr, "%s: Print Request Aborted - Unable to open %s\n",
  1507. X                       prog_name, current_config);
  1508. X      exit(7);
  1509. X    }
  1510. X
  1511. X   longjmpret(print, 1);
  1512. X }
  1513. X
  1514. X
  1515. X
  1516. Xvoid sysdelfunc()
  1517. X {
  1518. X   signal(SIGINT, sysdelfunc);
  1519. X   signal(SIGQUIT, SIG_IGN);
  1520. X   longjmpret(sys, 1);
  1521. X }
  1522. X
  1523. X
  1524. X
  1525. X#ifdef EXTERN
  1526. X
  1527. Xvoid extdelfunc()
  1528. X {
  1529. X   signal(SIGINT, extdelfunc);
  1530. X   signal(SIGQUIT, SIG_IGN);
  1531. X   longjmpret(ext, 1);
  1532. X }
  1533. X
  1534. X#endif
  1535. X
  1536. X
  1537. Xvoid printjob(pjargc, pjargv)
  1538. X int  pjargc;
  1539. X char *pjargv[];
  1540. X {
  1541. X  char  command[BUFSIZ], files[BUFSIZ-50], flags[138];
  1542. X  bool  file_found = FALSE, found_at_least_one = FALSE;
  1543. X  index n;
  1544. X
  1545. X
  1546. X   files[0] = '\0';
  1547. X   for(n = 0; n < pjargc; n++)
  1548. X    {
  1549. X      if(! setcom)
  1550. X       {
  1551. X         if((report = fopen(pjargv[n],"r")) == NULL)
  1552. X          {
  1553. X            fprintf(stderr,"%s: Cannot open %s\n", prog_name, pjargv[n]);
  1554. X            exit_status = 2;
  1555. X            file_found = FALSE;
  1556. X          }
  1557. X         else
  1558. X          {
  1559. X            fclose(report);
  1560. X            found_at_least_one = TRUE;
  1561. X            file_found = TRUE;
  1562. X            exit_status = 0;
  1563. X          }
  1564. X       }
  1565. X
  1566. X      if((file_found) || (setcom))
  1567. X        sprintf(files, "%s %s", files, pjargv[n]);
  1568. X      else
  1569. X        pjargv[n][0] = '\0';
  1570. X    }
  1571. X
  1572. X   flags[0] = '\0';
  1573. X   if((found_at_least_one) || (setcom))
  1574. X    {
  1575. X      if(remote_printer)
  1576. X       {
  1577. X         if((setcom) && (pjargc == 0))
  1578. X         {
  1579. X         proc_id = getpid();
  1580. X
  1581. X         sprintf(command, 
  1582. X          "cat > /tmp/ispi%d << \\EOF%c#!/bin/sh%c cat > /tmp/$$.pr%c echo \"%s\"%c copeez=%d%c while [ $copeez -ge 1 ]%c do%c cat /tmp/$$.pr%c copeez=`expr $copeez - 1`%c done%c echo \"%s\"%c rm /tmp/$$.pr%c exit%cEOF%c chmod 755 /tmp/ispi%d%c%c",
  1583. X          proc_id, '\n', '\n', '\n', t_ptr->on, '\n', copies, '\n', '\n', '\n', '\n', '\n', '\n', t_ptr->off, '\n', '\n', '\n', '\n', proc_id, '\n', '\0');
  1584. X
  1585. X         system(command);
  1586. X         sprintf(command,"/tmp/ispi%d", proc_id);
  1587. X
  1588. X         }
  1589. X         else
  1590. X         {
  1591. X
  1592. X          sprintf(command,
  1593. X           "sh -c \'echo \"%s\"%c copeez=%d%c while [ $copeez -ge 1 ]%c do%c cat %s%c copeez=`expr $copeez - 1`%c done%c echo \"%s\"%c exit%c%c\'",
  1594. X           t_ptr->on, '\n', copies, '\n', '\n', '\n', files, '\n', '\n', '\n', t_ptr->off, '\n', '\n', '\0');
  1595. X
  1596. X         }
  1597. X
  1598. X
  1599. X       }
  1600. X
  1601. X      else if((strcmp(curr_system,sys_name->nodename)) == 0)
  1602. X       {
  1603. X         if(copy)
  1604. X          strcat(flags, "-c ");
  1605. X         if(mail)
  1606. X          strcat(flags, "-m ");
  1607. X
  1608. X         if(lp)
  1609. X          {
  1610. X            if(banner)
  1611. X              strcat(flags, "-tt");
  1612. X#           ifdef EXTERN
  1613. X            if(externs)
  1614. X              sprintf(flags, "%s -o\"%s\"", flags, address);
  1615. X#           endif
  1616. X            sprintf(command,"lp %s -n%d -s -d%s %s",
  1617. X                            flags, copies, printer, files);
  1618. X          }
  1619. X         else
  1620. X          {
  1621. X            if(! banner)
  1622. X              strcat(flags, "-nb");
  1623. X#           ifdef EXTERN
  1624. X            if(externs)
  1625. X              sprintf(flags, "%s -d \"%s\"", flags, address);
  1626. X#           endif
  1627. X            sprintf(command,"nq %s -t %d -q %s %s",
  1628. X                           flags, copies, printer, files);
  1629. X          }
  1630. X       }
  1631. X#    ifdef UUCP
  1632. X      else
  1633. X       {
  1634. X         if(mail)
  1635. X          strcat(flags, "-m ");
  1636. X         if(banner && lp)
  1637. X          strcat(flags, "-tt");
  1638. X         else if((! banner) && (! lp))
  1639. X          strcat(flags, "-nb");
  1640. X
  1641. X         command[0] = '\0';
  1642. X         if((pjargc == 0) && (setcom))
  1643. X          {
  1644. X            if(lp)
  1645. X              sprintf(command,"%s - %s\\! lp %s -c -n%d -s -d%s",
  1646. X                    UUX, curr_system, flags, copies, printer);
  1647. X            else
  1648. X              sprintf(command,"%s - %s\\! nq %s -c -t %d -q %s",
  1649. X                    UUX, curr_system, flags, copies, printer);
  1650. X          }
  1651. X         else for(n = 0; n < pjargc; n++)
  1652. X          {
  1653. X           if(pjargv[n][0] != '\0')
  1654. X            {
  1655. X             if(lp)
  1656. X               sprintf(command,"%scat %s | %s - %s\\! lp %s -c -n%d -s -d%s ; ",
  1657. X                 command, pjargv[n], UUX, curr_system, flags, copies, printer);
  1658. X             else
  1659. X               sprintf(command,"%scat %s | %s - %s\\! nq %s -c -t %d -q %s ; ",
  1660. X                 command, pjargv[n], UUX, curr_system, flags, copies, printer);
  1661. X            }
  1662. X          }
  1663. X       }
  1664. X#     endif
  1665. X    }
  1666. X
  1667. X    if(setcom)
  1668. X      fprintf(stdout,"%s",command);
  1669. X    else if(found_at_least_one)
  1670. X      exit_status = system(command);
  1671. X    else
  1672. X      exit_status = 2;
  1673. X }
  1674. X
  1675. X#ifdef XFER
  1676. Xvoid xfer_it(vargc, vargv)
  1677. X int  vargc;
  1678. X char *vargv[];
  1679. X {
  1680. X  index n;
  1681. X  char sistum[BUFSIZ];
  1682. X
  1683. X   fclose(config);
  1684. X
  1685. X   for(n = 0; n < vargc; n++)
  1686. X    {
  1687. X      if((report = fopen(vargv[n],"r")) == NULL)
  1688. X       {
  1689. X         clear_scr();
  1690. X         fprintf(tty,"\n\n\n%s: Cannot open %s\n\n\n", prog_name, vargv[n]);
  1691. X       }
  1692. X      else
  1693. X       {
  1694. X         clear_scr();
  1695. X         sprintf(sistum, "%s %s", xfer_cmd, vargv[n]);
  1696. X         fprintf(tty, "\n\n\n\n\n%s", sistum);
  1697. X         fprintf(tty, "\n\n\nABORT this routine if you are ");
  1698. X         fprintf(tty, "not prepared to start the receiving process.");
  1699. X         fprintf(tty, "\n\n\n\n<RETURN> to Begin - <DEL> to Abort ");
  1700. X         fflush(tty);
  1701. X         while((getc(stdin)) != '\n');
  1702. X         sleep(10);
  1703. X         system(sistum);
  1704. X         fclose(report);
  1705. X       }
  1706. X      fprintf(tty, "<RETURN> to Continue ");
  1707. X      fflush(tty);
  1708. X      while((getc(stdin)) != '\n');
  1709. X    }
  1710. X   if((config = fopen(current_config,"r")) == NULL)
  1711. X    {
  1712. X      fprintf(stderr, "%s: Print Request Aborted - Unable to open %s\n",
  1713. X                       prog_name, current_config);
  1714. X      exit(7);
  1715. X    }
  1716. X
  1717. X }
  1718. X#endif
  1719. END_OF_FILE
  1720. if test 43525 -ne `wc -c <'ISPI/ispi.c'`; then
  1721.     echo shar: \"'ISPI/ispi.c'\" unpacked with wrong size!
  1722. fi
  1723. # end of 'ISPI/ispi.c'
  1724. fi
  1725. if test -f 'ISPI/UUSTUFF.dr/SYS_III.dr/uustart.c' -a "${1}" != "-c" ; then 
  1726.   echo shar: Will not clobber existing file \"'ISPI/UUSTUFF.dr/SYS_III.dr/uustart.c'\"
  1727. else
  1728. echo shar: Extracting \"'ISPI/UUSTUFF.dr/SYS_III.dr/uustart.c'\" \(4318 characters\)
  1729. sed "s/^X//" >'ISPI/UUSTUFF.dr/SYS_III.dr/uustart.c' <<'END_OF_FILE'
  1730. X/*  UUSTART                                */
  1731. X/*        THIS IS UUSTART FOR THE MODEL 31 ZILOG            */
  1732. X/*        This program is designed to invoke uucico on a more    */
  1733. X/*    regular basis than would be possible via cron.                  */
  1734. X/*                                    */
  1735. X/*    The program copies itself into a child process and runs        */
  1736. X/*    continuously without tying up the user's terminal.  The        */
  1737. X/*    program starts uucico at the requested interval.                */
  1738. X/*                                    */
  1739. X/*      This timing and invocation routine is adapted from "monitor"    */
  1740. X/*      which was written by:                        */
  1741. X/*                                    */
  1742. X/*               John Withers                        */
  1743. X/*        IRS (Springfield District)                */
  1744. X/*        Phone:    FTS 955-4842                    */
  1745. X/*                                    */
  1746. X/*                                    */
  1747. X/*      UUSTART was written by:                        */
  1748. X/*        Larry Bartz                                             */
  1749. X/*        IRS (Indianapolis District)                             */
  1750. X/*        Phone: FTS 331-6796                                     */
  1751. X/*                                    */
  1752. X/*    Date:    December 30, 1986                    */
  1753. X/*                                    */
  1754. X/*                                    */
  1755. X
  1756. X#include <stdio.h>
  1757. X#include <time.h>
  1758. X#include <ssignal.h>
  1759. X
  1760. X/*  User adjustable constants for "uustart.c"                  */
  1761. X
  1762. X/* Define the execution window, STIME to ETIME on DAY1 through DAY2      */
  1763. X
  1764. X#define STIME 25200    /* Daily starting time 6:00 AM (sec past midnight)*/
  1765. X#define ETIME 64800    /* Daily ending time 7:00 PM (sec past midnight)  */
  1766. X#define DAY1  0        /* Starting day of the week, (Sun = 0)          */
  1767. X#define DAY2  6        /* Ending day of the week (Sun = 0)          */
  1768. X
  1769. X/* Define the interval between samples                      */
  1770. X
  1771. X#define INTV  120    /* Interval between invocations [2 min](in seconds)*/
  1772. X
  1773. X
  1774. Xmain()
  1775. X
  1776. X{
  1777. X
  1778. X
  1779. X  int pid,
  1780. X      status,
  1781. X      child,
  1782. X      parent,
  1783. X      fork();
  1784. X
  1785. X  long last_time,
  1786. X       curtime,
  1787. X       stop();
  1788. X
  1789. X/* On with the show                            */
  1790. X
  1791. X  signal(SIGHUP, SIG_IGN);    /* Ignore 'Hang-up' signals        */
  1792. X  signal(SIGINT, SIG_IGN);    /* Ignore 'Interrupt' signals        */
  1793. X  signal(SIGQUIT,SIG_IGN);    /* Ignore 'Quit' signals        */
  1794. X
  1795. X  switch (pid = fork())        /* Switch to child process        */
  1796. X  {
  1797. X    case 0:            /* In child process, all ok        */
  1798. X        break;
  1799. X
  1800. X    case -1:        /* In parent process with error        */
  1801. X        sysmsg("uustart: fork failed");
  1802. X        exit(1);
  1803. X
  1804. X    default:        /* In parent process, all ok        */
  1805. X        exit(0);
  1806. X  }
  1807. X
  1808. X  last_time = stop(INTV);    /* Wait until on interval get time    */
  1809. X
  1810. X
  1811. X  for(;;)
  1812. X  {
  1813. X    curtime = stop(INTV);    /* Wait for interval, get current time    */
  1814. X
  1815. X    last_time = curtime;
  1816. X
  1817. X    if (checktime(curtime) == 0) continue;
  1818. X
  1819. X    switch(child = fork())
  1820. X    {
  1821. X        case -1:
  1822. X            sysmsg("uustart - fork failed");
  1823. X            break;
  1824. X
  1825. X        case 0:        /* Child process            */
  1826. X            execlp("/usr/lib/uucp/uucico","uucico","-r1",NULL);
  1827. X            sysmsg("uustart - exec failed");
  1828. X            break;
  1829. X
  1830. X        default:
  1831. X            parent = wait(&status);
  1832. X            break;
  1833. X    }
  1834. X  }
  1835. X}
  1836. X
  1837. X/*  STOP                                */
  1838. X/*    This function stops the current process until the next even    */
  1839. X/*    'interval' (e.g. next quarter hour).  The function returns    */
  1840. X/*    the current system time as its functional value            */
  1841. X
  1842. Xlong stop(interval)
  1843. X
  1844. Xint interval;
  1845. X
  1846. X{
  1847. X  int intrtn();
  1848. X
  1849. X  unsigned length;
  1850. X
  1851. X  long now, time();
  1852. X
  1853. X  now = time((long *) 0);
  1854. X
  1855. X  length = ((now / interval) + 1) * interval - now;
  1856. X
  1857. X  signal(SIGALRM, intrtn);
  1858. X  alarm(length);
  1859. X  pause();
  1860. X  return(time((long *) 0));
  1861. X}
  1862. X
  1863. X/* INTRTN                                */
  1864. X/*  This function is present to allow for alarm clock signal trapping    */
  1865. Xintrtn()
  1866. X{return;}
  1867. X
  1868. Xint checktime(when)
  1869. X
  1870. Xlong when;
  1871. X
  1872. X{
  1873. X  extern long timezone;        /* Seconds adjustment for time zone    */
  1874. X
  1875. X  extern int  daylight;        /* TRUE if daylight savings time    */
  1876. X
  1877. X  int wday,
  1878. X      flag = 1;
  1879. X
  1880. X  long now;
  1881. X
  1882. X  tzset();            /* Set the time zone adjustment        */
  1883. X
  1884. X  when -= timezone;        /* Adjust for local time        */
  1885. X
  1886. X  if (daylight) when += 3600;    /* Adjust for daylight saving time    */
  1887. X
  1888. X  now = when % 86400;        /* Seconds since midnight        */
  1889. X
  1890. X  if (now < (STIME + INTV) || now > ETIME) flag = 0;
  1891. X
  1892. X  wday = ((when / 86400) + 4) % 7;
  1893. X
  1894. X  if (wday < DAY1 || wday > DAY2) flag = 0;
  1895. X
  1896. X  return(flag);
  1897. X}
  1898. X
  1899. Xsysmsg(msg)
  1900. X
  1901. Xchar *msg;
  1902. X
  1903. X{
  1904. X  extern int     errno,
  1905. X        deverr,
  1906. X        sys_nerr;
  1907. X
  1908. X  extern char    *sys_errlist[];
  1909. X
  1910. X  struct tm *x, *localtime();
  1911. X
  1912. X  long now, time();
  1913. X
  1914. X  now = time((long *) 0);
  1915. X
  1916. X  x = localtime(&now);
  1917. X
  1918. X  fprintf(stderr,"%02d/%02d/%02d %02d:%02d:%02d - ",
  1919. X    x->tm_mon+1, x->tm_mday, x->tm_year, x->tm_hour, x->tm_min, x->tm_sec);
  1920. X
  1921. X  fprintf(stderr,msg);
  1922. X
  1923. X  if (errno <= sys_nerr)
  1924. X    fprintf(stderr, " (%s)\n", sys_errlist[errno]);
  1925. X  else
  1926. X    fprintf(stderr, " (Error %d)\n", errno);
  1927. X
  1928. X  fflush(stderr);
  1929. X}
  1930. END_OF_FILE
  1931. if test 4318 -ne `wc -c <'ISPI/UUSTUFF.dr/SYS_III.dr/uustart.c'`; then
  1932.     echo shar: \"'ISPI/UUSTUFF.dr/SYS_III.dr/uustart.c'\" unpacked with wrong size!
  1933. fi
  1934. chmod +x 'ISPI/UUSTUFF.dr/SYS_III.dr/uustart.c'
  1935. # end of 'ISPI/UUSTUFF.dr/SYS_III.dr/uustart.c'
  1936. fi
  1937. if test -f 'ISPI/UUSTUFF.dr/SYS_V.dr/uustart.c' -a "${1}" != "-c" ; then 
  1938.   echo shar: Will not clobber existing file \"'ISPI/UUSTUFF.dr/SYS_V.dr/uustart.c'\"
  1939. else
  1940. echo shar: Extracting \"'ISPI/UUSTUFF.dr/SYS_V.dr/uustart.c'\" \(5192 characters\)
  1941. sed "s/^X//" >'ISPI/UUSTUFF.dr/SYS_V.dr/uustart.c' <<'END_OF_FILE'
  1942. X/*  UUSTART                                */
  1943. X/*        This program is designed to invoke uucico on a more    */
  1944. X/*    regular basis than would be possible via cron.                  */
  1945. X/*                                    */
  1946. X/*    The program copies itself into a child process and runs        */
  1947. X/*    continuously without tying up the user's terminal.  The        */
  1948. X/*    program starts uucico at the requested interval.                */
  1949. X/*                                    */
  1950. X/*      This timing and invocation routine is adapted from "monitor"    */
  1951. X/*      which was written by:                        */
  1952. X/*                                    */
  1953. X/*               John Withers                        */
  1954. X/*        IRS (Springfield District)                */
  1955. X/*        Phone:    FTS 955-4842                    */
  1956. X/*                                    */
  1957. X/*                                    */
  1958. X/*      UUSTART was written by:                        */
  1959. X/*        Larry Bartz                                             */
  1960. X/*        IRS (Indianapolis District)                             */
  1961. X/*        Phone: FTS 331-6796                                     */
  1962. X/*                                    */
  1963. X/*    Date:    December 30, 1986                    */
  1964. X/*                                    */
  1965. X/*                                    */
  1966. X/*                                    */
  1967. X/*    MODIFICATION:                            */
  1968. X/*                                    */
  1969. X/*        This version calls a C-shell script "uuscout.csh"       */
  1970. X/*        instead of invoking uucico directly. This is necc-    */
  1971. X/*        essary in System V UNIX because uucico will not        */
  1972. X/*        execute without the "-ssys" specification. Version    */
  1973. X/*        III (ZEUS) UNIX's uucico permitted a "-r1" invok-    */
  1974. X/*        ation without "-ssys", in which case only those        */
  1975. X/*        systems for which work was queued would be called.    */
  1976. X/*        We don't want to waste time and system resources    */
  1977. X/*        calling systems for which no work is queued, so        */
  1978. X/*        we employ uuscout.csh to determine for which sys-    */
  1979. X/*        tems work is queued and then invoke uucico only        */
  1980. X/*        for them.                        */
  1981. X/*                                    */
  1982. X/*        Larry Bartz                                             */
  1983. X/*        IRS (Indianapolis District)                             */
  1984. X/*        Phone: FTS 331-6796                                     */
  1985. X/*                                    */
  1986. X/*    Date:    February 19, 1987                    */
  1987. X/*                                    */
  1988. X
  1989. X#include <stdio.h>
  1990. X#include <time.h>
  1991. X#include <signal.h>
  1992. X
  1993. X/*  User adjustable constants for "uustart.c"                  */
  1994. X
  1995. X/* Define the execution window, STIME to ETIME on DAY1 through DAY2      */
  1996. X
  1997. X#define STIME 25200    /* Daily starting time 6:00 AM (sec past midnight)*/
  1998. X#define ETIME 64800    /* Daily ending time 7:00 PM (sec past midnight)  */
  1999. X#define DAY1  0        /* Starting day of the week, (Sun = 0)          */
  2000. X#define DAY2  6        /* Ending day of the week (Sun = 0)          */
  2001. X
  2002. X/* Define the interval between samples                      */
  2003. X
  2004. X#define INTV  120    /* Interval between invocations [2 min](in seconds)*/
  2005. X
  2006. X
  2007. Xmain()
  2008. X
  2009. X{
  2010. X
  2011. X
  2012. X  int pid,
  2013. X      status,
  2014. X      child,
  2015. X      parent,
  2016. X      fork();
  2017. X
  2018. X  long last_time,
  2019. X       curtime,
  2020. X       stop();
  2021. X
  2022. X/* On with the show                            */
  2023. X
  2024. X  signal(SIGHUP, SIG_IGN);    /* Ignore 'Hang-up' signals        */
  2025. X  signal(SIGINT, SIG_IGN);    /* Ignore 'Interrupt' signals        */
  2026. X  signal(SIGQUIT,SIG_IGN);    /* Ignore 'Quit' signals        */
  2027. X
  2028. X  switch (pid = fork())        /* Switch to child process        */
  2029. X  {
  2030. X    case 0:            /* In child process, all ok        */
  2031. X        break;
  2032. X
  2033. X    case -1:        /* In parent process with error        */
  2034. X        sysmsg("uustart: fork failed");
  2035. X        exit(1);
  2036. X
  2037. X    default:        /* In parent process, all ok        */
  2038. X        exit(0);
  2039. X  }
  2040. X
  2041. X  last_time = stop(INTV);    /* Wait until on interval get time    */
  2042. X
  2043. X
  2044. X  for(;;)
  2045. X  {
  2046. X    curtime = stop(INTV);    /* Wait for interval, get current time    */
  2047. X
  2048. X    last_time = curtime;
  2049. X
  2050. X    if (checktime(curtime) == 0) continue;
  2051. X
  2052. X    switch(child = fork())
  2053. X    {
  2054. X        case -1:
  2055. X            sysmsg("uustart - fork failed");
  2056. X            break;
  2057. X
  2058. X        case 0:        /* Child process            */
  2059. X            system("/usr/lib/uucp/uuscout.csh");
  2060. X            exit(0);
  2061. X
  2062. X        default:
  2063. X            parent = wait(&status);
  2064. X            break;
  2065. X    }
  2066. X  }
  2067. X}
  2068. X
  2069. X/*  STOP                                */
  2070. X/*    This function stops the current process until the next even    */
  2071. X/*    'interval' (e.g. next quarter hour).  The function returns    */
  2072. X/*    the current system time as its functional value            */
  2073. X
  2074. Xlong stop(interval)
  2075. X
  2076. Xint interval;
  2077. X
  2078. X{
  2079. X  int intrtn();
  2080. X
  2081. X  unsigned length;
  2082. X
  2083. X  long now, time();
  2084. X
  2085. X  now = time((long *) 0);
  2086. X
  2087. X  length = ((now / interval) + 1) * interval - now;
  2088. X
  2089. X  signal(SIGALRM, intrtn);
  2090. X  alarm(length);
  2091. X  pause();
  2092. X  return(time((long *) 0));
  2093. X}
  2094. X
  2095. X/* INTRTN                                */
  2096. X/*  This function is present to allow for alarm clock signal trapping    */
  2097. Xintrtn()
  2098. X{return;}
  2099. X
  2100. Xint checktime(when)
  2101. X
  2102. Xlong when;
  2103. X
  2104. X{
  2105. X  extern long timezone;        /* Seconds adjustment for time zone    */
  2106. X
  2107. X  extern int  daylight;        /* TRUE if daylight savings time    */
  2108. X
  2109. X  int wday,
  2110. X      flag = 1;
  2111. X
  2112. X  long now;
  2113. X
  2114. X  tzset();            /* Set the time zone adjustment        */
  2115. X
  2116. X  when -= timezone;        /* Adjust for local time        */
  2117. X
  2118. X  if (daylight) when += 3600;    /* Adjust for daylight saving time    */
  2119. X
  2120. X  now = when % 86400;        /* Seconds since midnight        */
  2121. X
  2122. X  if (now < (STIME + INTV) || now > ETIME) flag = 0;
  2123. X
  2124. X  wday = ((when / 86400) + 4) % 7;
  2125. X
  2126. X  if (wday < DAY1 || wday > DAY2) flag = 0;
  2127. X
  2128. X  return(flag);
  2129. X}
  2130. X
  2131. Xsysmsg(msg)
  2132. X
  2133. Xchar *msg;
  2134. X
  2135. X{
  2136. X  extern int     errno,
  2137. X        deverr,
  2138. X        sys_nerr;
  2139. X
  2140. X  extern char    *sys_errlist[];
  2141. X
  2142. X  struct tm *x, *localtime();
  2143. X
  2144. X  long now, time();
  2145. X
  2146. X  now = time((long *) 0);
  2147. X
  2148. X  x = localtime(&now);
  2149. X
  2150. X  fprintf(stderr,"%02d/%02d/%02d %02d:%02d:%02d - ",
  2151. X    x->tm_mon+1, x->tm_mday, x->tm_year, x->tm_hour, x->tm_min, x->tm_sec);
  2152. X
  2153. X  fprintf(stderr,msg);
  2154. X
  2155. X  if (errno <= sys_nerr)
  2156. X    fprintf(stderr, " (%s)\n", sys_errlist[errno]);
  2157. X  else
  2158. X    fprintf(stderr, " (Error %d)\n", errno);
  2159. X
  2160. X  fflush(stderr);
  2161. X}
  2162. END_OF_FILE
  2163. if test 5192 -ne `wc -c <'ISPI/UUSTUFF.dr/SYS_V.dr/uustart.c'`; then
  2164.     echo shar: \"'ISPI/UUSTUFF.dr/SYS_V.dr/uustart.c'\" unpacked with wrong size!
  2165. fi
  2166. chmod +x 'ISPI/UUSTUFF.dr/SYS_V.dr/uustart.c'
  2167. # end of 'ISPI/UUSTUFF.dr/SYS_V.dr/uustart.c'
  2168. fi
  2169. echo shar: End of archive 2 \(of 15\).
  2170. cp /dev/null ark2isdone
  2171. MISSING=""
  2172. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ; do
  2173.     if test ! -f ark${I}isdone ; then
  2174.     MISSING="${MISSING} ${I}"
  2175.     fi
  2176. done
  2177. if test "${MISSING}" = "" ; then
  2178.     echo You have unpacked all 15 archives.
  2179.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2180. else
  2181.     echo You still need to unpack the following archives:
  2182.     echo "        " ${MISSING}
  2183. fi
  2184. ##  End of shell archive.
  2185. exit 0
  2186.  
  2187.