home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume32 / xbbs / part04 < prev    next >
Encoding:
Text File  |  1992-09-08  |  64.9 KB  |  2,982 lines

  1. Newsgroups: comp.sources.misc
  2. From: sandy@godzilla.Quotron.COM (Sanford Zelkovitz)
  3. Subject:  v32i019:  xbbs - A Bulletin Board System for System V, Part04/11
  4. Message-ID: <1992Sep9.045002.26032@sparky.imd.sterling.com>
  5. X-Md4-Signature: 7ec3d9bbe307f44a95de02ae07869c1e
  6. Date: Wed, 9 Sep 1992 04:50:02 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: sandy@godzilla.Quotron.COM (Sanford Zelkovitz)
  10. Posting-number: Volume 32, Issue 19
  11. Archive-name: xbbs/part04
  12. Environment: SYSV, Xenix
  13.  
  14. #! /bin/sh
  15. # This is a shell archive.  Remove anything before this line, then feed it
  16. # into a shell via "sh file" or similar.  To overwrite existing files,
  17. # type "sh file -c".
  18. # Contents:  bbsc1.c.A checksum.c today/sun.c
  19. # Wrapped by kent@sparky on Fri Sep  4 12:48:49 1992
  20. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  21. echo If this archive is complete, you will see the following message:
  22. echo '          "shar: End of archive 4 (of 11)."'
  23. if test -f 'bbsc1.c.A' -a "${1}" != "-c" ; then 
  24.   echo shar: Will not clobber existing file \"'bbsc1.c.A'\"
  25. else
  26.   echo shar: Extracting \"'bbsc1.c.A'\" \(39960 characters\)
  27.   sed "s/^X//" >'bbsc1.c.A' <<'END_OF_FILE'
  28. X/*
  29. X * bbsc.c 
  30. X *
  31. X * BBS (Bulletin Board System) written in xenix system V  "C". 
  32. X *
  33. X * Support files needed: bbscdef.h bbscport.o or bbscport.c bbsclock.o or
  34. X * bbsclock.c bbscfile.o or bbscfile.c bbscmisc.o or bbscmisc.c bbscio.o   or
  35. X * bbscio.c bbscarea.o or bbscarea.c bbscmsga.o or bbscmsga.c bbscqust.o or
  36. X * bbscqust.c bbscbult.o or bbscbult.c bbscadds.o or bbscadds.c bbsclist.o or
  37. X * bbsclist.c bbsczip.o  or bbsczip.c bbscconf.c or bbscconf.o bbscsumm.c or
  38. X * .o 
  39. X *
  40. X *
  41. X *                          Sanford J. Zelkovitz
  42. X *
  43. X */
  44. X#include "bbsc12.h"
  45. Xchar *basename();
  46. Xlong difft();
  47. Xmain()
  48. X{
  49. X    int             i, fd;
  50. X    char            ptype[2];
  51. X    char            pval[18];
  52. X    /*
  53. X     * init global variables 
  54. X     */
  55. X    Zsec = Ztime = sigreturn = 0;
  56. X    if ((inbuf = fopen(CONFIG, "r")) == NULL) {
  57. X        portsout("\n\rError opening configuration file!\n\r");
  58. X        exit(1);
  59. X    }
  60. X    if ((fgets(WELCOME, 49, inbuf) == NULL))
  61. X        error_config();
  62. X    strip(WELCOME);
  63. X    if ((fgets(BULLETINS, 49, inbuf) == NULL))
  64. X        error_config();
  65. X    strip(BULLETINS);
  66. X    if ((fgets(NEWUSER, 49, inbuf) == NULL))
  67. X        error_config();
  68. X    strip(NEWUSER);
  69. X    if ((fgets(SYSTEM, 49, inbuf) == NULL))
  70. X        error_config();
  71. X    strip(SYSTEM);
  72. X    if ((fgets(CALLERS, 49, inbuf) == NULL))
  73. X        error_config();
  74. X    strip(CALLERS);
  75. X    if ((fgets(LASTCALL, 49, inbuf) == NULL))
  76. X        error_config();
  77. X    strip(LASTCALL);
  78. X    if ((fgets(USERS, 49, inbuf) == NULL))
  79. X        error_config();
  80. X    strip(USERS);
  81. X    if ((fgets(UNIXMSG, 49, inbuf) == NULL))
  82. X        error_config();
  83. X    strip(UNIXMSG);
  84. X    if ((fgets(DLMSG, 49, inbuf) == NULL))
  85. X        error_config();
  86. X    strip(DLMSG);
  87. X    if ((fgets(HUMOR, 49, inbuf) == NULL))
  88. X        error_config();
  89. X    strip(HUMOR);
  90. X    if ((fgets(HELP, 49, inbuf) == NULL))
  91. X        error_config();
  92. X    strip(HELP);
  93. X    if ((fgets(HELPFILE, 49, inbuf) == NULL))
  94. X        error_config();
  95. X    strip(HELPFILE);
  96. X    if ((fgets(HELPMSG, 49, inbuf) == NULL))
  97. X        error_config();
  98. X    strip(HELPMSG);
  99. X    if ((fgets(USERPRIV, 49, inbuf) == NULL))
  100. X        error_config();
  101. X    strip(USERPRIV);
  102. X    if ((fgets(MAINPRIV, 49, inbuf) == NULL))
  103. X        error_config();
  104. X    strip(MAINPRIV);
  105. X    if ((fgets(FILEPRIV, 49, inbuf) == NULL))
  106. X        error_config();
  107. X    strip(FILEPRIV);
  108. X    if ((fgets(QUESTION, 49, inbuf) == NULL))
  109. X        error_config();
  110. X    strip(QUESTION);
  111. X    if ((fgets(ANSWER, 49, inbuf) == NULL))
  112. X        error_config();
  113. X    strip(ANSWER);
  114. X    if ((fgets(ADDITN, 49, inbuf) == NULL))
  115. X        error_config();
  116. X    strip(ADDITN);
  117. X    if ((fgets(LISTFILES, 49, inbuf) == NULL))
  118. X        error_config();
  119. X    strip(LISTFILES);
  120. X    if ((fgets(TODAY, 98, inbuf) == NULL))
  121. X        error_config();
  122. X    strip(TODAY);
  123. X    if ((fgets(ORGPATH, 49, inbuf) == NULL))
  124. X        error_config();
  125. X    strip(ORGPATH);
  126. X    if ((fgets(AREAS, 49, inbuf) == NULL))
  127. X        error_config();
  128. X    strip(AREAS);
  129. X
  130. X    strcpy(SIGS, ORGPATH);
  131. X    strcat(SIGS, "sigs.bbs");
  132. X
  133. X    if ((fgets(MSGS, 49, inbuf) == NULL))
  134. X        error_config();
  135. X    strip(MSGS);
  136. X    if ((fgets(USRBBS, 49, inbuf) == NULL))
  137. X        error_config();
  138. X    strip(USRBBS);
  139. X    if ((fgets(RB, 49, inbuf) == NULL))
  140. X        error_config();
  141. X    strip(RB);
  142. X    if ((fgets(SB, 49, inbuf) == NULL))
  143. X        error_config();
  144. X    strip(SB);
  145. X    if ((fgets(CRCR, 49, inbuf) == NULL))
  146. X        error_config();
  147. X    strip(CRCR);
  148. X    if ((fgets(CRCS, 49, inbuf) == NULL))
  149. X        error_config();
  150. X    strip(CRCS);
  151. X    if ((fgets(YMDR, 49, inbuf) == NULL))
  152. X        error_config();
  153. X    strip(YMDR);
  154. X    if ((fgets(YMDS, 49, inbuf) == NULL))
  155. X        error_config();
  156. X    strip(YMDS);
  157. X    if ((fgets(YMR, 49, inbuf) == NULL))
  158. X        error_config();
  159. X    strip(YMR);
  160. X    if ((fgets(YMS, 49, inbuf) == NULL))
  161. X        error_config();
  162. X    strip(YMS);
  163. X    if ((fgets(RZ, 49, inbuf) == NULL))
  164. X        error_config();
  165. X    strip(RZ);
  166. X    if ((fgets(SZ, 49, inbuf) == NULL))
  167. X        error_config();
  168. X    strip(SZ);
  169. X    if ((fgets(KS, 49, inbuf) == NULL))
  170. X        error_config();
  171. X    strip(KS);
  172. X    if ((fgets(KRA, 49, inbuf) == NULL))
  173. X        error_config();
  174. X    strip(KRA);
  175. X    if ((fgets(KRE, 49, inbuf) == NULL))
  176. X        error_config();
  177. X    strip(KRE);
  178. X    if ((fgets(SEAR, 49, inbuf) == NULL))
  179. X        error_config();
  180. X    strip(SEAR);
  181. X    if ((fgets(SEAS, 49, inbuf) == NULL))
  182. X        error_config();
  183. X    strip(SEAS);
  184. X    if ((fgets(SYSOP, 49, inbuf) == NULL))
  185. X        error_config();
  186. X    strip(SYSOP);
  187. X    if ((fgets(buf128, 49, inbuf) == NULL))
  188. X        error_config();
  189. X    strip(buf128);
  190. X    LOGTIME = atoi(buf128);
  191. X    if ((fgets(buf128, 49, inbuf) == NULL))
  192. X        error_config();
  193. X    strip(buf128);
  194. X    RUNTIME = atoi(buf128);
  195. X    if ((fgets(buf128, 49, inbuf) == NULL))
  196. X        error_config();
  197. X    strip(buf128);
  198. X    WAITTIME = atoi(buf128);
  199. X    if ((fgets(buf128, 49, inbuf) == NULL))
  200. X        error_config();
  201. X    strip(buf128);
  202. X    NEWPRIV = atoi(buf128);
  203. X    if ((fgets(buf128, 49, inbuf) == NULL))
  204. X        error_config();
  205. X    strip(buf128);
  206. X    MAXPRIV = atoi(buf128);
  207. X    if ((fgets(buf128, 49, inbuf) == NULL))
  208. X        error_config();
  209. X    strip(buf128);
  210. X    MAXSEC = atoi(buf128);
  211. X    if ((fgets(buf128, 49, inbuf) == NULL))
  212. X        error_config();
  213. X    strip(buf128);
  214. X    MAXKBYTE = atoi(buf128);
  215. X    if ((fgets(TAR, 49, inbuf) == NULL))
  216. X        error_config();
  217. X    strip(TAR);
  218. X    if ((fgets(ZCAT, 49, inbuf) == NULL))
  219. X        error_config();
  220. X    strip(ZCAT);
  221. X/*
  222. X    Starting with version 7.102, the following fgets can just get garbage
  223. X       since the arc file lister is now a built-in ( bbscarc.c )
  224. X*/ 
  225. X    if ((fgets(ARC, 49, inbuf) == NULL))
  226. X        error_config();
  227. X    strip(ARC);
  228. X
  229. X/*
  230. X    Starting with version 7.102, the following fgets can just get garbage
  231. X       since the zip file lister is now a built-in ( bbscunzip.c )
  232. X*/ 
  233. X    if ((fgets(ZIP, 49, inbuf) == NULL))
  234. X        error_config();
  235. X    strip(ZIP);
  236. X
  237. X    if ((fgets(MONITOR, 29, inbuf) == NULL))
  238. X        error_config();
  239. X    strip(MONITOR);
  240. X    if ((fgets(CONSOLE, 29, inbuf) == NULL))
  241. X        error_config();
  242. X    strip(CONSOLE);
  243. X    if ((fgets(SHELL, 29, inbuf) == NULL))
  244. X        error_config();
  245. X    strip(SHELL);
  246. X    if ((fgets(buf128, 49, inbuf) == NULL))
  247. X        error_config();
  248. X    strip(buf128);
  249. X    scan = atoi(buf128);
  250. X    if ((fgets(READN, 98, inbuf) == NULL))
  251. X        error_config();
  252. X    strip(READN);
  253. X    if ((fgets(POSTN, 98, inbuf) == NULL))
  254. X        error_config();
  255. X    strip(POSTN);
  256. X    fclose(inbuf);
  257. X
  258. X    strcpy(l_m_base, "0");
  259. X    strcpy(l_f_base, "0");
  260. X    strcpy(xprt_a, "0");
  261. X    strcpy(tggl_a, "1");
  262. X
  263. X    maxkbyte = MAXKBYTE;
  264. X    logtime = LOGTIME;
  265. X    Ytime = logtime;
  266. X    runtime = RUNTIME;
  267. X    waittime = WAITTIME;
  268. X    newpriv = NEWPRIV;
  269. X    max_priv = MAXPRIV;
  270. X    strcpy(callers, CALLERS);
  271. X    this_ttyname = ttyname(0);
  272. X    strcpy(buf128, this_ttyname);
  273. X    i = strlen(buf128);
  274. X    i--;
  275. X    substr(buf128, pval, i, 2);
  276. X    strcat(callers, pval);
  277. X    strcpy(port_id, pval);
  278. X    strcpy(buf128, "/tmp/conf");
  279. X    strcat(buf128, pval);
  280. X    (void) unlink(buf128);
  281. X    strcpy( buf128, ORGPATH );
  282. X    strcat( buf128, "inval_port.bbs");
  283. X    inbuf = fopen(buf128, "r" );
  284. X    if( inbuf != NULL ) {
  285. X        while (1) {
  286. X            if( fscanf(inbuf, "%s", buf128) == EOF )
  287. X                break;
  288. X            if(strcmp(basename(buf128),basename(this_ttyname))==0){
  289. X                fclose(inbuf);
  290. X                portinit();
  291. X                setmodes();
  292. X                portsout("\n\r\n\rYou called in on a restricted line!\n\r\n\r");
  293. X                restoremodes();
  294. X                portrst();
  295. X                strcpy(buf128, ORGPATH);
  296. X                strcat(buf128, "restricted.bbs");
  297. X                if((inbuf=fopen(buf128,"a")) != NULL) {
  298. X                    gettime(ttime);
  299. X                    GeTdAtE(mm, dd, yy, month, day, year, date, week);
  300. X                    fd = atoi(mm);
  301. X                    fd++;
  302. X                    sprintf(mm, "%.2d", fd);
  303. X                    (void)fprintf(inbuf, "%s/%s/%s  %s    restricted line caller on %s\n", mm,dd,yy,ttime,this_ttyname);
  304. X                    fclose(inbuf);
  305. X                }
  306. X                exit(1);
  307. X            }
  308. X        }
  309. X        fclose(inbuf);
  310. X    }
  311. X    hold_pipe = FALSE;
  312. X    debug = FALSE;
  313. X    hold_off = FALSE;
  314. X    toggle_hold = FALSE;
  315. X    first_time_in = TRUE;
  316. X    first_msg_in = TRUE;
  317. X    chat_in_progress = FALSE;
  318. X    stop_chat = FALSE;
  319. X    newuzr = FALSE;
  320. X    statcnt = 0;
  321. X    last_msg_read = 0;
  322. X    xpert = FALSE;
  323. X    listed_l = FALSE;
  324. X    listed_r = FALSE;
  325. X    listed_n = FALSE;
  326. X    toggle = TRUE;
  327. X    active = TRUE;
  328. X    reply_sw = FALSE;
  329. X    end_msg = FALSE;
  330. X    read_flag = FALSE;
  331. X    sys_flag = FALSE;
  332. X    strcpy(old_upath, AUTHOR);
  333. X    new_msg = 0;
  334. X    c_pathname[0] = '\0';
  335. X    if_monitor = FALSE;
  336. X    no_cntrl_k = FALSE;
  337. X    resp_flag = FALSE;
  338. X    in_the_buffer = 0;
  339. X    user_priv = 1;
  340. X    read_number = 1;
  341. X    extra_time = 0L;
  342. X    extra_size = 0L;
  343. X    dload_total = 0L;
  344. X    max_dload = 0L;
  345. X    blocked_m = 0;
  346. X    mpA = 1;
  347. X    mpB = 1;
  348. X    mpE = 1;
  349. X    mpG = 1;
  350. X    mpK = 1;
  351. X    mpP = 1;
  352. X    mpN = 1;
  353. X    mpQ = 1;
  354. X    mpR = 1;
  355. X    mpS = 1;
  356. X    mpW = 1;
  357. X    mpM = 1;
  358. X    mpX = 1;
  359. X    mpF = 1;
  360. X    mpC = 1;
  361. X    mpH = 1;
  362. X    mpT = 1;
  363. X    mpD = 1;
  364. X    mpY = 1;
  365. X
  366. X    mpUSENET = 1;        /* added for 7.2.1 */
  367. X    mpRF = 1;
  368. X    mpQUEST = 1;
  369. X    mpU = 32767;
  370. X    mpMS = 1;
  371. X    mpCHAT = 1;
  372. X    mpCONF = 1;
  373. X    mpL = 1;
  374. X    fpL = 1;
  375. X    fpU = 1;
  376. X    fpD = 1;
  377. X    fpM = 1;
  378. X    fpG = 1;
  379. X    fpR = 1;
  380. X
  381. X
  382. X    strcpy(buf128, STDERR);
  383. X    strcat(buf128, port_id);
  384. X    STDerr = freopen(buf128, "w+", stderr);
  385. X    if (IF_MONITOR) {
  386. X        mon_handle = open(MONITOR, O_WRONLY);
  387. X        if (mon_handle == -1) {
  388. X            portsout("\n\rCritical Error --- End BBS\n\r");
  389. X            exit(1);
  390. X        }
  391. X        if_monitor = FALSE;
  392. X        i = getpid();
  393. X        itoa(buf128, i);
  394. X        strcpy(who_am_i, "/tmp/pid");
  395. X        strcat(who_am_i, pval);
  396. X        inbuf = fopen(who_am_i, "w");
  397. X        fprintf(inbuf, "%s", buf128);
  398. X        fclose(inbuf);
  399. X    }
  400. X    if ((inbuf = fopen(MAINPRIV, "r")) == NULL) {
  401. X        portsout("\n\rCritical Error!\n\r");
  402. X        portsout("Unable to find main privs!\n\r");
  403. X        exit(1);
  404. X    }
  405. X    while (fscanf(inbuf, "%s%s", ptype, pval) != EOF) {
  406. X        ptype[1] = '\0';
  407. X        *ptype = toupper(*ptype);
  408. X        switch (ptype[0]) {
  409. X        case ('B'):
  410. X            mpB = atoi(pval);
  411. X            break;
  412. X        case ('E'):
  413. X            mpE = atoi(pval);
  414. X            break;
  415. X        case ('G'):
  416. X            mpG = atoi(pval);
  417. X            break;
  418. X        case ('K'):
  419. X            mpK = atoi(pval);
  420. X            break;
  421. X        case ('N'):
  422. X            mpN = atoi(pval);
  423. X            break;
  424. X        case ('Q'):
  425. X            mpQ = atoi(pval);
  426. X            break;
  427. X        case ('R'):
  428. X            mpR = atoi(pval);
  429. X            break;
  430. X        case ('S'):
  431. X            mpS = atoi(pval);
  432. X            break;
  433. X        case ('W'):
  434. X            mpW = atoi(pval);
  435. X            break;
  436. X        case ('M'):
  437. X            mpM = atoi(pval);
  438. X            break;
  439. X        case ('X'):
  440. X            mpX = atoi(pval);
  441. X            break;
  442. X        case ('F'):
  443. X            mpF = atoi(pval);
  444. X            break;
  445. X        case ('C'):
  446. X            mpC = atoi(pval);
  447. X            break;
  448. X        case ('H'):
  449. X            mpH = atoi(pval);
  450. X            break;
  451. X        case ('T'):
  452. X            mpT = atoi(pval);
  453. X            break;
  454. X        case ('D'):
  455. X            mpD = atoi(pval);
  456. X            break;
  457. X        case ('Y'):
  458. X            mpY = atoi(pval);
  459. X            break;
  460. X        case ('U'):
  461. X            mpU = atoi(pval);
  462. X            break;
  463. X        case ('P'):
  464. X            mpP = atoi(pval);
  465. X            break;
  466. X        case ('A'):
  467. X            mpA = atoi(pval);
  468. X            break;
  469. X        case ('L'):
  470. X            mpL = atoi(pval);
  471. X            break;
  472. X        case ('&'):
  473. X            mpMS = atoi(pval);
  474. X            break;
  475. X        case ('?'):
  476. X            mpZ = atoi(pval);
  477. X            break;
  478. X        case ('~'):
  479. X            mpCHAT = atoi(pval);
  480. X            break;
  481. X        case ('%'):
  482. X            mpQUEST = atoi(pval);
  483. X            break;
  484. X        case ('$'):
  485. X            mpRF = atoi(pval);
  486. X            break;
  487. X        case ('O'):
  488. X            mpCONF = atoi(pval);
  489. X            break;
  490. X        case ('I'):    /* added for 7.2.1 */
  491. X            mpUSENET = atoi(pval);
  492. X            break;
  493. X        default:
  494. X            portsout("\n\rBad entry in MAIN PRIV\n\r");
  495. X            break;
  496. X        }
  497. X    }
  498. X    fclose(inbuf);
  499. X    if ((inbuf = fopen(FILEPRIV, "r")) == NULL) {
  500. X        portsout("\n\rCritical Error!\n\r");
  501. X        portsout("Unable to find file privs!\n\r");
  502. X        exit(1);
  503. X    }
  504. X    while (fscanf(inbuf, "%s%s", ptype, pval) != EOF) {
  505. X        ptype[1] = '\0';
  506. X        *ptype = toupper(*ptype);
  507. X        switch (ptype[0]) {
  508. X        case ('L'):
  509. X            fpL = atoi(pval);
  510. X            break;
  511. X        case ('U'):
  512. X            fpU = atoi(pval);
  513. X            break;
  514. X        case ('D'):
  515. X            fpD = atoi(pval);
  516. X            break;
  517. X        case ('M'):
  518. X            fpM = atoi(pval);
  519. X            break;
  520. X        case ('G'):
  521. X            fpG = atoi(pval);
  522. X            break;
  523. X        case ('R'):
  524. X            fpR = atoi(pval);
  525. X            break;
  526. X        default:
  527. X            portsout("\n\rBad entry in FILE PRIV\n\r");
  528. X            break;
  529. X        }
  530. X    }
  531. X    fclose(inbuf);
  532. X    w_fname[0] = '\0';
  533. X    w_lname[0] = '\0';
  534. X    strcpy(w_password, "MPK0");
  535. X
  536. X    u_fname[0] = '\0';
  537. X    u_lname[0] = '\0';
  538. X    strcpy(u_password, "MPK0");
  539. X    u_time1[0] = '\0';
  540. X    u_date1[0] = '\0';
  541. X    u_time2[0] = '\0';
  542. X    u_date2[0] = '\0';
  543. X    u_city[0] = '\0';
  544. X
  545. X    mm[0] = '\0';
  546. X    dd[0] = '\0';
  547. X    yy[0] = '\0';
  548. X    month[0] = '\0';
  549. X    day[0] = '\0';
  550. X    year[0] = '\0';
  551. X    date[0] = '\0';
  552. X    week[0] = '\0';
  553. X    ttime[0] = '\0';
  554. X
  555. X    strcpy(msg_delete, "0");
  556. X    msg_no[0] = '\0';
  557. X    msg_date[0] = '\0';
  558. X    msg_date[0] = '\0';
  559. X    msg_time[0] = '\0';
  560. X    msg_to[0] = '\0';
  561. X    msg_from[0] = '\0';
  562. X    msg_pass[0] = '\0';
  563. X    msg_subject[0] = '\0';
  564. X    msg_text[0] = '\0';
  565. X    strfill(msg_text, 0, 1482);
  566. X
  567. X    stop_that = FALSE;
  568. X
  569. X    /* get date and time from the clock      */
  570. X
  571. X    gettime(ttime);
  572. X    GeTdAtE(mm, dd, yy, month, day, year, date, week);
  573. X    substr(month, mnd, 1, 3);
  574. X    strcat(mnd, day);
  575. X
  576. X    fd = atoi(mm);
  577. X    fd++;
  578. X    sprintf(mm, "%.2d", fd);
  579. X
  580. X    sec = logtime;
  581. X    which_timer = 1;
  582. X    alarm(sec);
  583. X
  584. X    if (signal(SIGALRM, timer) == (int (*) ()) -1)
  585. X        exit(1);
  586. X    if (signal(SIGUSR1, mon_toggle) == (int (*) ()) -1)
  587. X        exit(1);
  588. X    if (signal(SIGUSR2, sys_toggle) == (int (*) ()) -1)
  589. X        exit(1);
  590. X    if (signal(SIGPIPE, chat) == (int (*) ()) -1)
  591. X        exit(1);
  592. X    if (signal(SIGINT, STOP) == (int (*) ()) -1)
  593. X        exit(1);
  594. X    if (signal(SIGHUP, hanged) == (int (*) ()) -1)
  595. X        exit(1);
  596. X
  597. X
  598. X    portinit();        /* init terminal modes */
  599. X    setmodes();
  600. X    signon();
  601. X    driver();
  602. X    restoremodes();
  603. X    portrst();        /* undo any special modes */
  604. X    closer(1);
  605. X}
  606. X/* end of mainline routine       */
  607. X
  608. Xdriver()
  609. X{
  610. X    char            linebuf[MAXLINE], buf[128], *bufptr,    /* ptr to buf */
  611. X                    usercd[100],    /* user record */
  612. X                   *userptr,/* ptr to usercd */
  613. X                    cmd[2];
  614. X
  615. X    int             cnt, ok_sw, case_sw, i, mpk, result, num0, num1, num2;
  616. X    long            vtime;
  617. X
  618. X    mpk = mpK;
  619. X    cnt = 0;
  620. X    ok_sw = TRUE;
  621. X    bufptr = buf;
  622. X    cmd[0] = '\0';
  623. X    if (active) {
  624. X
  625. X        sec = runtime;
  626. X        vtime = sec;
  627. X        vtime += extra_time;
  628. X        if (vtime > 32767L)
  629. X            vtime = 32767L;
  630. X        if (vtime < 60L)
  631. X            vtime = 60L;
  632. X        sec = vtime;
  633. X        Ytime = sec;
  634. X        max_dload = ((long) (maxkbyte)) * 1024L;
  635. X        max_dload += extra_size;
  636. X        alarm(sec);
  637. X        which_timer = 2;
  638. X        change_bult();
  639. X        today_msg();
  640. X        if (scan) {
  641. X            if (!newuzr) {
  642. X                portsout("\n\rLast time you were on the system: ");
  643. X                portsout(z_date);
  644. X                portsout(" at ");
  645. X                portsout(z_time);
  646. X                portsout("\n\r\n\r");
  647. X                portsout("\n\rDo you wish to check to see if you have any messages? (Y/n): ");
  648. X                portsin(cmd, 1);
  649. X                portsout(CRLF);
  650. X                if (cmd[0] == 'N' || cmd[0] == 'n')
  651. X                    check_msga_n();
  652. X                else
  653. X                    check_msga();
  654. X                cmd[0] = '\0';
  655. X            } else {
  656. X                portsout(CRLF);
  657. X                portsout("Since you are a new user, the scan for messages will not be performed.\n\r");
  658. X                portsout("The next time that you call, all message bases will be scanned.\n\r\n\r");
  659. X                check_msga_n();
  660. X                portsout("Since you are a new user, you will be asked to fill out our questionnaire.\n\r");
  661. X                portsout("Please take the time and fill it out. Thank you.\n\r");
  662. X                question(1);
  663. X            }
  664. X        } else
  665. X            check_msga_n();
  666. X    }
  667. X    while (active) {
  668. X        stop_that = FALSE;    /* reset switch */
  669. X        portsout(CRLF);
  670. X        signal(SIGALRM, timer);
  671. X        signal(SIGUSR1, mon_toggle);
  672. X        signal(SIGUSR2, sys_toggle);
  673. X        signal(SIGPIPE, chat);
  674. X        signal(SIGINT, STOP);
  675. X        signal(SIGHUP, hanged);
  676. X        cmd_t();
  677. X        sigreturn = 0;
  678. X        bbsmenu(1,0);
  679. X        portsin(cmd, 1);
  680. X        portsout(CRLF);
  681. X
  682. X        *cmd = toupper(*cmd);
  683. X
  684. X        switch (cmd[0]) {
  685. X        case ('V'):
  686. X            portsout("\n\r\n\rVersion: ");
  687. X            portsout(VERSION);
  688. X            portsout("    ");
  689. X            portsout(LASTDATE);
  690. X            portsout("\n\r\n\r");
  691. X            break;
  692. X        case ('U'):
  693. X            if (!privmsg(mpU))
  694. X                break;
  695. X            cmd_p(UNIXMSG);
  696. X            if ((inbuf = fopen(callers, "a")) == NULL) {    /* create or open for
  697. X                                     * append */
  698. X                portsout(CRLF);
  699. X                portsout("Can't open/create callers file!");
  700. X                portsout(CRLF);
  701. X                return;
  702. X            }
  703. X            result = fprintf(inbuf, "%s", "   Going into Xenix/Unix");
  704. X            if (result < 0) {
  705. X                portsout(CRLF);
  706. X                portsout("Caller file has problem writing");
  707. X                portsout(CRLF);
  708. X            } else {
  709. X                fputs("\n", inbuf);
  710. X            }
  711. X            fclose(inbuf);
  712. X            restoremodes();
  713. X            portrst();
  714. X            STDerr = freopen("/dev/tty", "w+", stderr);
  715. X            result = system(SHELL);
  716. X            strcpy(buf128, STDERR);
  717. X            strcat(buf128, port_id);
  718. X            STDerr = freopen(buf128, "w+", stderr);
  719. X            signal(SIGALRM, timer);
  720. X            signal(SIGHUP, hanged);
  721. X            signal(SIGUSR1, mon_toggle);
  722. X            signal(SIGUSR2, sys_toggle);
  723. X            signal(SIGPIPE, chat);
  724. X            signal(SIGINT, STOP);
  725. X            portinit();
  726. X            setmodes();
  727. X            break;
  728. X        case ('G'):    /* goodby */
  729. X            if (!privmsg(mpG))
  730. X                break;
  731. X            cmd_c();
  732. X            break;
  733. X        case ('L'):
  734. X            if (!privmsg(mpL))
  735. X                break;
  736. X            who_is_there();
  737. X            break;
  738. X        case ('Z'):
  739. X            if (!privmsg(mpY))
  740. X                break;
  741. X            cmd_z();
  742. X            break;
  743. X        case ('R'):
  744. X            if (!privmsg(mpRF))
  745. X                break;
  746. X            file_list();
  747. X            break;
  748. X        case ('C'):
  749. X            if (!privmsg(mpCHAT))
  750. X                break;
  751. X            sigchat();
  752. X            break;
  753. X        case ('O'):
  754. X            if (!privmsg(mpCONF))
  755. X                break;
  756. X            conf();
  757. X            break;
  758. X        case ('E'):
  759. X            if (!privmsg(mpCONF))
  760. X                break;
  761. X            portsout("\n\r\n\rThe following users are presently in conference\n\r");
  762. X            no_cntrl_k = 1;
  763. X            strcpy(buf128, "ls /tmp/conf* > /tmp/inconf.");
  764. X            strcat(buf128, port_id);
  765. X            (void) system(buf128);
  766. X            strcpy(buf128, "/tmp/inconf.");
  767. X            strcat(buf128, port_id);
  768. X            if ((otbuf = fopen(buf128, "r")) == NULL) {
  769. X                portsout("\n\rError opening list file!\n\r");
  770. X                exit(1);
  771. X            }
  772. X            while (fscanf(otbuf, "%s", who_am_i) != EOF)
  773. X                cmd_p(who_am_i);
  774. X            fclose(otbuf);
  775. X            no_cntrl_k = 0;
  776. X            break;
  777. X        case ('I'):        /* No need to check privs since
  778. X                                           each command has access privs */
  779. X            sig_access();
  780. X            break;
  781. X        case ('Q'):
  782. X            if (!privmsg(mpQUEST))
  783. X                break;
  784. X            question(0);
  785. X            break;
  786. X        case ('A'):
  787. X            if (!privmsg(mpA))
  788. X                break;
  789. X            additional(ADDITN);
  790. X            break;
  791. X        case ('D'):
  792. X            if (!privmsg(mpD))
  793. X                break;
  794. X            strcpy(buf128, TODAY);
  795. X            strcat(buf128, port_id);
  796. X            result = system(buf128);
  797. X            strcpy(buf128, "/tmp/today");
  798. X            strcat(buf128, port_id);
  799. X            cmd_p(buf128);
  800. X            break;
  801. X        case ('P'):
  802. X            if (!privmsg(mpP))
  803. X                break;
  804. X            ch_password();
  805. X            break;
  806. X        case ('X'):    /* expert toggle */
  807. X            if (!privmsg(mpX))
  808. X                break;
  809. X            cmd_x();
  810. X            rewritx();
  811. X            break;
  812. X        case ('N'):    /* print new-user stuff */
  813. X            if (!privmsg(mpN))
  814. X                break;
  815. X            cmd_p(NEWUSER);
  816. X            break;
  817. X        case ('W'):    /* print welcome file */
  818. X            if (!privmsg(mpW))
  819. X                break;
  820. X            cmd_p(WELCOME);
  821. X            break;
  822. X        case ('B'):    /* print bulletins */
  823. X            if (!privmsg(mpB))
  824. X                break;
  825. X            change_bult();
  826. X            break;
  827. X        case ('H'):    /* print humor file */
  828. X            if (!privmsg(mpH))
  829. X                break;
  830. X            cmd_p(HUMOR);
  831. X            break;
  832. X        case ('F'):
  833. X            if (!privmsg(mpF))
  834. X                break;
  835. X            cmd_f();
  836. X            break;
  837. X        case ('M'):
  838. X            if (!privmsg(mpMS))
  839. X                break;
  840. X            msg_section(mpk);
  841. X            break;
  842. X        case ('T'):
  843. X            if (!privmsg(mpT))
  844. X                break;
  845. X            toggle = !toggle;
  846. X            rewritx();
  847. X            if (toggle) {
  848. X                portsout("\n\rStop Mode\n\r");
  849. X            } else {
  850. X                portsout("\n\rContinuous Mode\n\r");
  851. X            }
  852. X            break;
  853. X        case ('?'):    /* help */
  854. X            if (!privmsg(mpZ))
  855. X                break;
  856. X            cmd_p(HELP);
  857. X            break;
  858. X        case ('S'):    /* added for 7.2.1  USENET ACCESS */
  859. X            if (!privmsg(mpUSENET))
  860. X                break;
  861. X            usenet();
  862. X            break;
  863. X        default:
  864. X            break;
  865. X        }
  866. X
  867. X    }
  868. X}
  869. X/* end of function               */
  870. Xsigchat()
  871. X{
  872. X    char           *ttyzz;
  873. X    char            tb[80];
  874. X    int             result, handle;
  875. X    static char     bell = '\007';
  876. X    if ((inbuf = fopen(callers, "a")) == NULL) {    /* create or open for
  877. X                             * append */
  878. X        portsout(CRLF);
  879. X        portsout("Can't open/create callers file!");
  880. X        portsout(CRLF);
  881. X        return;
  882. X    }
  883. X    result = fprintf(inbuf, "%s", "   Requesting a chat");
  884. X    if (result < 0) {
  885. X        portsout(CRLF);
  886. X        portsout("Caller file has problem writing");
  887. X        portsout(CRLF);
  888. X    } else {
  889. X        fputs("\n", inbuf);
  890. X    }
  891. X    fclose(inbuf);
  892. X    result = stat(SYSTTY, &statbuf);
  893. X    if (!result) {
  894. X        strcpy(buf128, "\n\r\n\r");
  895. X        strcat(buf128, SYSOP);
  896. X        strcat(buf128, " is already engaged in a chat or has turned it off.\n\r\n\r");
  897. X        portsout(buf128);
  898. X        return;
  899. X    }
  900. X    handle = open(CONSOLE, O_WRONLY);
  901. X    if (handle == -1) {
  902. X        portsout("\n\rError opening console driver!\n\r");
  903. X        exit(1);
  904. X    }
  905. X    ttyzz = ttyname(1);
  906. X    strcpy(tb, "\n\rChat requested by ");
  907. X    strcat(tb, w_fname);
  908. X    strcat(tb, " ");
  909. X    strcat(tb, w_lname);
  910. X    strcat(tb, " on ");
  911. X    strcat(tb, ttyzz);
  912. X    strcat(tb, "\n\r");
  913. X    write(handle, tb, (strlen(tb)));
  914. X    Xsec = 0;
  915. X    stop_chat = FALSE;
  916. X    portsout("\n\rPaging: ");
  917. X    for (result = 0; result <= 30; result++) {
  918. Xsigloop:
  919. X        if (stop_chat) {
  920. X            portsout(CRLF);
  921. X            close(handle);
  922. X            return;
  923. X        }
  924. X        Sec = alarm(0);
  925. X        hold_pipe = TRUE;
  926. X        alarm(Sec);
  927. X        hold_pipe = FALSE;
  928. X        if (Sec != Xsec) {
  929. X            if (stop_chat) {
  930. X                portsout(CRLF);
  931. X                close(handle);
  932. X                return;
  933. X            }
  934. X            Xsec = Sec;
  935. X            portsout(". ");
  936. X            write(handle, &bell, 1);
  937. X        } else
  938. X            goto sigloop;
  939. X    }
  940. X    strcpy(buf128, "\n\rI am sorry; however, ");
  941. X    strcat(buf128, SYSOP);
  942. X    strcat(buf128, " is unavailable to chat with you.\n\r");
  943. X    portsout(buf128);
  944. X    close(handle);
  945. X}
  946. X
  947. Xch_password()
  948. X{
  949. X    int             result, char_in_passwd;
  950. X    char           *pptr;
  951. X    while (1) {
  952. Xin_passx:
  953. X        portsout(CRLF);
  954. X        portsout("Ok, now I need a 4  to 10 character password ===> ");
  955. X        portsinz(u_password, 10);
  956. X        portsout(CRLF);
  957. X        char_in_passwd = strlen(u_password);
  958. X        if (char_in_passwd < 4) {
  959. X            portsout("\n\rPassword was NOT changed!\n\r");
  960. X            return;
  961. X        }
  962. X        pptr = strchr(u_password, '~');
  963. X        if (pptr != NULL) {
  964. X            portsout("\n\rInvalid password   try again!\n\r");
  965. X            goto in_passx;
  966. X        }
  967. X        pptr = strchr(u_password, ' ');
  968. X        if (pptr != NULL) {
  969. X            portsout("\n\rInvalid password   try again!\n\r");
  970. X            goto in_passx;
  971. X        }
  972. X        portsout("Just to make sure, enter it again ===> ");
  973. X        portsinz(w_password, 10);
  974. X        result = strlen(w_password);
  975. X        if (result != char_in_passwd)
  976. X            goto passwx_loop;
  977. X        portsout(CRLF);
  978. X
  979. X        if (strcmp(u_password, w_password) == 0) {
  980. X            result = 10 - result;
  981. X            while (result) {
  982. X                strcat(u_password, " ");
  983. X                result--;
  984. X            }
  985. X            break;    /* get it right twice, then get out */
  986. X        }
  987. Xpasswx_loop:
  988. X        portsout(CRLF);
  989. X        portsout("hmmmm, one of us forgot it already");
  990. X        portsout(CRLF);
  991. X        portsout("      let's try it again!!");
  992. X        portsout(CRLF);
  993. X        portsout(CRLF);
  994. X    }
  995. X    if ((inbuf = fopen(USERS, "r+")) == NULL) {
  996. X        portsout("\n\rError opening users file!\n\r");
  997. X        exit(1);
  998. X    }
  999. X    fds = fileno(inbuf);
  1000. X    rewind(inbuf);
  1001. X    locking(fds, LK_LOCK, 0L);
  1002. X    result = fseek(inbuf, save_d_pos, 0);
  1003. X    rewrtuser(inbuf);
  1004. X    rewind(inbuf);
  1005. X    locking(fds, LK_UNLCK, 0L);
  1006. X    fclose(inbuf);
  1007. X}
  1008. X
  1009. Xmsg_section(mpk)
  1010. X    int             mpk;
  1011. X{
  1012. X    char            cmd[81];
  1013. X    char        tmp_cmd[80];
  1014. X    char        *cmd_ptr, *tmp_cmd_ptr;
  1015. X    int             result, tmp_number;
  1016. X    char           *file_ptr_x;
  1017. X    if (first_msg_in) {
  1018. X        result = atoi(l_m_base);
  1019. X        change_msga(result);
  1020. X        check_mail();
  1021. X    }
  1022. X    first_msg_in = FALSE;
  1023. Xmsg_looper:
  1024. X    signal(SIGALRM, timer);
  1025. X    signal(SIGHUP, hanged);
  1026. X    signal(SIGUSR1, mon_toggle);
  1027. X    signal(SIGUSR2, sys_toggle);
  1028. X    signal(SIGPIPE, chat);
  1029. X    signal(SIGINT, STOP);
  1030. X    stop_that = FALSE;
  1031. X    cmd_t();
  1032. X    portsout("\n\rCurrent message area = ");
  1033. X    strcpy(buf128, m_pathname);
  1034. X    file_ptr_x = strrchr(buf128, '/');
  1035. X    *file_ptr_x = '\0';
  1036. X    file_ptr_x = strrchr(buf128, '/');
  1037. X    *file_ptr_x++;
  1038. X    strcpy(who_am_i, file_ptr_x);
  1039. X    portsout(who_am_i);
  1040. X    portsout(CRLF);
  1041. X    portsout(CRLF);
  1042. X    bbsmenu(2,mpk);
  1043. X    portsin_cmp(cmd, 80, "KkQqSsRrYyCcEeNnMmGgXxTt?");
  1044. X    portsout(CRLF);
  1045. X
  1046. X    if(cmd[0] != 'B' && cmd[0] != 'b')
  1047. X        fix_name(cmd);
  1048. X
  1049. X    switch (cmd[0]) {
  1050. X    case ('E'):        /* enter msg */
  1051. X        if (!privmsg(mpE))
  1052. X            goto msg_looper;
  1053. X        cmd_e();
  1054. X        goto msg_looper;
  1055. X    case ('N'):        /*Enter BLOCKED message */
  1056. X        if(!privmsg(mpE))
  1057. X            goto msg_looper;
  1058. X        blocked_m = 1;
  1059. X        cmd_e();
  1060. X        blocked_m = 0;
  1061. X        goto msg_looper;
  1062. X    case ('G'):        /* goodby */
  1063. X        if (!privmsg(mpG))
  1064. X            goto msg_looper;
  1065. X        cmd_c();
  1066. X        break;
  1067. X    case ('T'):
  1068. X        if (!privmsg(mpT))
  1069. X            goto msg_looper;
  1070. X        toggle = !toggle;
  1071. X        rewritx();
  1072. X        if (toggle) {
  1073. X            portsout("\n\rStop Mode\n\r");
  1074. X        } else {
  1075. X            portsout("\n\rContinuous Mode\n\r");
  1076. X        }
  1077. X        goto msg_looper;
  1078. X    case ('X'):
  1079. X        if (!privmsg(mpX))
  1080. X            goto msg_looper;
  1081. X        cmd_x();
  1082. X        rewritx();
  1083. X        goto msg_looper;
  1084. X    case ('K'):
  1085. X        if (!privmsg(mpk))
  1086. X            goto msg_looper;
  1087. X        cmd_k();
  1088. X        goto msg_looper;
  1089. X    case ('Q'):        /* quick scan */
  1090. X        if (!privmsg(mpQ))
  1091. X            goto msg_looper;
  1092. X        cmd_q();
  1093. X        goto msg_looper;
  1094. X    case ('R'):        /* read msg */
  1095. X        if (!privmsg(mpR))
  1096. X            goto msg_looper;
  1097. X        cmd_r();
  1098. X        goto msg_looper;
  1099. X    case ('B'):
  1100. X    case ('b'):
  1101. X        if(!privmsg(mpR))
  1102. X            goto msg_looper;
  1103. X        cmd_ptr = cmd;
  1104. X        cmd_ptr++;
  1105. X        tmp_number=strlen(cmd_ptr);
  1106. X        if(!tmp_number)
  1107. X            {
  1108. X            portsout("\n\r\n\rNo messages selected in batch command!\n\r\n\r");
  1109. X            goto msg_looper;
  1110. X            }
  1111. X        digit(cmd_ptr);
  1112. X        while(*cmd_ptr)
  1113. X            {
  1114. X            tmp_cmd_ptr = tmp_cmd;
  1115. X            if(*cmd_ptr == (char) ' ')
  1116. X                {
  1117. X                cmd_ptr++;
  1118. X                continue;
  1119. X                }
  1120. X            while(*cmd_ptr != (char) ' ')
  1121. X                {
  1122. X                if(*cmd_ptr == (char) '\0')
  1123. X                    break;
  1124. X                *tmp_cmd_ptr++ = *cmd_ptr++;
  1125. X                }
  1126. X            *tmp_cmd_ptr = (char)'\0';
  1127. X            read_number = atoi(tmp_cmd);
  1128. X            read_flag = TRUE;
  1129. X            cmd_r();
  1130. X            read_flag = FALSE;
  1131. X            portsout(CRLF);
  1132. X            portsout("*** Depress a key to continue ( control-k to quit ) ........ ");
  1133. X            jnk[0] = portin();
  1134. X            if (jnk[0] == CTL_K || stop_that)
  1135. X                {
  1136. X                stop_that = FALSE;
  1137. X                goto msg_looper;
  1138. X                }
  1139. X                
  1140. X            }
  1141. X        goto msg_looper;
  1142. X            
  1143. X        
  1144. X    case ('Y'):
  1145. X        if (!privmsg(mpY))
  1146. X            goto msg_looper;
  1147. X        cmd_y();
  1148. X        goto msg_looper;
  1149. X    case ('S'):        /* scan msg */
  1150. X        if (!privmsg(mpS))
  1151. X            goto msg_looper;
  1152. X        cmd_s();
  1153. X        goto msg_looper;
  1154. X    case ('C'):
  1155. X        if (!privmsg(mpC))
  1156. X            goto msg_looper;
  1157. X        check_mail();
  1158. X        goto msg_looper;
  1159. X    case ('M'):
  1160. X        break;
  1161. X    case ('?'):        /* help */
  1162. X        if (!privmsg(mpZ))
  1163. X            goto msg_looper;
  1164. X        cmd_p(HELPMSG);
  1165. X        goto msg_looper;
  1166. X    case ('A'):
  1167. X        result = strlen(cmd);
  1168. X        result--;
  1169. X        if (!result)
  1170. X            change_msga(0);
  1171. X        else {
  1172. X            substr(cmd, buf128, 2, result);
  1173. X            digit(buf128);
  1174. X            result = atoi(buf128);
  1175. X            change_msga(result);
  1176. X        }
  1177. X        check_mail();
  1178. X        goto msg_looper;
  1179. X    default:
  1180. X        goto msg_looper;
  1181. X    }
  1182. X}
  1183. X
  1184. Xprivmsg(priv)
  1185. X    int             priv;
  1186. X{
  1187. X    if (user_priv >= priv)
  1188. X        return (TRUE);
  1189. X    portsout("\n\rI'm sorry, your privilege level is not high enough to use that option.\n\r");
  1190. X    return (FALSE);
  1191. X}
  1192. Xcmd_c()
  1193. X{                /* go to the operating system level */
  1194. X    char            well[3];
  1195. X    int             length;
  1196. X    if (resp_flag) {
  1197. X        portsout("\n\r\n\rAre you sure you want to exit? (Y/n): ");
  1198. X        portsin(well, 1);
  1199. X        portsout(CRLF);
  1200. X        if (well[0] == 'N' || well[0] == 'n')
  1201. X            return;
  1202. X    }
  1203. X    length = strlen(c_pathname);
  1204. X    if (resp_flag && length > 0) {
  1205. X        portsout(CRLF);
  1206. X        strcpy(buf128, "Would you like to leave a private message for ");
  1207. X        strcat(buf128, SYSOP);
  1208. X        strcat(buf128, "? (y/N): ");
  1209. X        portsout(buf128);
  1210. X        portsin(well, 1);
  1211. X        portsout(CRLF);
  1212. X        if (well[0] == 'y' || well[0] == 'Y') {
  1213. X            portsout("\n\rDo you wish to use blocked (right justified) format?  (y/N: ");
  1214. X            portsin(well, 1);
  1215. X            portsout(CRLF);
  1216. X            if (well[0] == 'y' || well[0] == 'Y') 
  1217. X                blocked_m = 1;
  1218. X            else
  1219. X                blocked_m = 0;
  1220. X            strcpy(m_pathname, c_pathname);
  1221. X            hdrread();
  1222. X            reply_sw = TRUE;
  1223. X            strcpy(msg_to, SYSOP);
  1224. X            strcpy(msg_subject, "Departure Message");
  1225. X            end_msg = TRUE;
  1226. X            cmd_e();
  1227. X            reply_sw = FALSE;
  1228. X        }
  1229. X    }
  1230. X    if ((inbuf = fopen(SYSTEM, "r")) == NULL) {
  1231. X        portsout("\n\rError opening system file!\n\r");
  1232. X        exit(1);
  1233. X    } else {
  1234. X        no_cntrl_k = TRUE;
  1235. X        porttype(inbuf);/* type a file to port */
  1236. X        fclose(inbuf);
  1237. X    }
  1238. X    active = FALSE;
  1239. X}
  1240. X/* end of function               */
  1241. Xcmd_t()
  1242. X{
  1243. X    int             minutes, seconds;
  1244. X    xsec = alarm(0);
  1245. X    sec = xsec;
  1246. X    alarm(sec);
  1247. X    minutes = xsec / 60;
  1248. X    seconds = xsec - (minutes * 60);
  1249. X    portsout(CRLF);
  1250. X    portsout("Time left = ");
  1251. X    itoa(bufy, minutes);
  1252. X    strcpy(bufx, bufy);
  1253. X    strcat(bufx, " minutes and ");
  1254. X    itoa(bufy, seconds);
  1255. X    strcat(bufx, bufy);
  1256. X    strcat(bufx, " seconds");
  1257. X    portsout(bufx);
  1258. X    portsout(CRLF);
  1259. X}
  1260. X
  1261. Xcmd_tt(tt) int tt;
  1262. X{
  1263. X    int             minutes, seconds;
  1264. X    long        tottime;
  1265. X    tottime = difft();
  1266. X    minutes = (int)tottime / 60L;
  1267. X    seconds = (int)tottime - (long)(minutes * 60);
  1268. X    itoa(bufy, minutes);
  1269. X    strcpy(bufx, bufy);
  1270. X    strcat(bufx, " minutes and ");
  1271. X    itoa(bufy, seconds);
  1272. X    strcat(bufx, bufy);
  1273. X    strcat(bufx, " seconds");
  1274. X}
  1275. X
  1276. Xint
  1277. Xtimer()
  1278. X{
  1279. X    portsout(CRLF);
  1280. X    if (which_timer == 1)
  1281. X        portsout("Your login time limit has been reached!");
  1282. X    if (which_timer == 2)
  1283. X        portsout("Your usage time limit has been reached!");
  1284. X    if (which_timer == 3)
  1285. X        portsout("Your response time limit has been reached!");
  1286. X    portsout(CRLF);
  1287. X    restoremodes();
  1288. X    portrst();        /* undo any special modes */
  1289. X    closer(2);
  1290. X    exit(1);
  1291. X}
  1292. Xint
  1293. Xhanged()
  1294. X{
  1295. X    restoremodes();
  1296. X    portrst();
  1297. X    closer(3);
  1298. X    exit(1);
  1299. X}
  1300. X
  1301. Xcloser(typeclose)
  1302. Xint typeclose;
  1303. X{
  1304. X    int result;
  1305. X    if(typeclose == 2)
  1306. X        cmd_tt(0);
  1307. X    else
  1308. X        cmd_tt(1);
  1309. X    if ((inbuf = fopen(callers, "a")) == NULL)
  1310. X        exit(1);
  1311. X    result = fprintf(inbuf, "Time used on the system = %s\n",bufx);
  1312. X    if (result < 0)
  1313. X        exit(1);
  1314. X    switch(typeclose) {
  1315. X    case (1): fprintf(inbuf, "Normal exit .....\n");
  1316. X            break;
  1317. X    case (2): fprintf(inbuf, "Limit exit .....");
  1318. X            switch (which_timer) {
  1319. X            case(1): fprintf(inbuf, "logon\n");
  1320. X                break;
  1321. X            case(2): fprintf(inbuf, "usage\n");
  1322. X                break;
  1323. X            case(3): fprintf(inbuf, "response\n");
  1324. X                break;
  1325. X            }
  1326. X            break;
  1327. X    case (3): fprintf(inbuf, "The user just hung up! .....\n");
  1328. X            break;
  1329. X    case (4): fprintf(inbuf, "The user forgot his password! .....\n");
  1330. X            break;
  1331. X    default:  fprintf(inbuf, "Ooooops .... This exit is not known! .....\n");
  1332. X            break;
  1333. X    }
  1334. X
  1335. X    fprintf(inbuf,"\n\n");
  1336. X    fclose(inbuf);
  1337. X}
  1338. Xint
  1339. Xmon_toggle()
  1340. X{
  1341. X    signal(SIGUSR1, mon_toggle);
  1342. X    if (!chat_in_progress)
  1343. X        if_monitor = !if_monitor;
  1344. X    else
  1345. X        chat_in_progress = !chat_in_progress;
  1346. X}
  1347. Xint
  1348. XSTOP()
  1349. X{
  1350. X    signal(SIGINT, STOP);
  1351. X    stop_that = TRUE;
  1352. X}
  1353. Xint
  1354. Xchat()
  1355. X{
  1356. X    FILE           *dev;
  1357. X    int             result, handle;
  1358. X    char            byte, byten, byter, bytes, device[30];
  1359. X    signal(SIGPIPE, chat);
  1360. X    byten = (char) '\n';
  1361. X    byter = (char) '\r';
  1362. X    bytes = (char) ' ';
  1363. X    chat_in_progress = TRUE;
  1364. X    stop_chat = TRUE;
  1365. X    if (hold_pipe) {
  1366. X        alarm(Sec);
  1367. X        hold_pipe = FALSE;
  1368. X    }
  1369. X    Xsec = alarm(0);
  1370. X    if ((dev = fopen(SYSTTY, "r")) == NULL) {
  1371. X        portsout_chat("\n\rError finding sysop's device driver!\n\r");
  1372. X        exit(1);
  1373. X    }
  1374. X    if ((fgets(device, 29, dev) == NULL)) {
  1375. X        portsout_chat("\n\rError reading sysop's device driver name!\n\r");
  1376. X        exit(1);
  1377. X    }
  1378. X    fclose(dev);
  1379. X    strip(device);
  1380. X    handle = open(device, O_WRONLY);
  1381. X    if (handle == -1) {
  1382. X        portsout_chat("\n\rError opening sysop's device driver!\n\r");
  1383. X        exit(1);
  1384. X    }
  1385. X    portsout_chat(CRLF);
  1386. X    portsout_chat(CRLF);
  1387. X    portsout_chat(CRLF);
  1388. X    portsout_chat("********** THE SYSOP HAS STARTED CHAT MODE ********");
  1389. X    portsout_chat(CRLF);
  1390. X    portsout_chat("*** Your usage time has stopped during the chat ***");
  1391. X    portsout_chat(CRLF);
  1392. X    portsout_chat(CRLF);
  1393. X    portsout_chat(CRLF);
  1394. X    while (chat_in_progress) {
  1395. X        byte = portin_chat();
  1396. X        if (byte == 127)
  1397. X            byte = '\b';
  1398. X        portout_chat(byte);
  1399. X        if (byte == '\n')
  1400. X            portout_chat(byter);
  1401. X        if (byte == '\r')
  1402. X            portout_chat(byten);
  1403. X        write(handle, &byte, 1);
  1404. X        if (byte == '\n')
  1405. X            write(handle, &byter, 1);
  1406. X        if (byte == '\r')
  1407. X            write(handle, &byten, 1);
  1408. X        if (byte == '\b') {
  1409. X            write(handle, &bytes, 1);
  1410. X            portout_chat(bytes);
  1411. X            write(handle, &byte, 1);
  1412. X            portout_chat(byte);
  1413. X        }
  1414. X    }
  1415. X    close(handle);
  1416. X    portsout_chat(CRLF);
  1417. X    portsout_chat(CRLF);
  1418. X    portsout_chat(CRLF);
  1419. X    portsout_chat("********** THE SYSOP HAS STOPPED CHAT MODE **********");
  1420. X    portsout_chat(CRLF);
  1421. X    portsout_chat(CRLF);
  1422. X    portsout_chat(CRLF);
  1423. X    alarm(Xsec);
  1424. X}
  1425. X
  1426. Xint
  1427. Xsys_toggle()
  1428. X{
  1429. X    signal(SIGUSR2, sys_toggle);
  1430. X    if (!toggle_hold && hold_off) {
  1431. X        toggle_hold = TRUE;
  1432. X        return;
  1433. X    }
  1434. X    toggle_hold = FALSE;
  1435. X    if (!sys_flag) {
  1436. X        old_priv = user_priv;
  1437. X        user_priv = max_priv;
  1438. X        if (max_priv != MAXPRIV) {
  1439. X            sprintf(buf128, "\n\rCompiler error max=%d  MAX=%d\n\r", max_priv, MAXPRIV);
  1440. X            portsout(buf128);
  1441. X            exit(1);
  1442. X        }
  1443. X        strcpy(old_upath, u_pathname);
  1444. X        strcpy(old_fpath, f_pathname);
  1445. X        strcpy(old_mpath, m_pathname);
  1446. X        old_sec = alarm(0);
  1447. X        alarm(MAXSEC);
  1448. X    } else {
  1449. X        user_priv = old_priv;
  1450. X        strcpy(u_pathname, old_upath);
  1451. X        strcpy(f_pathname, old_fpath);
  1452. X        strcpy(m_pathname, old_mpath);
  1453. X        if (!first_msg_in)
  1454. X            hdrread();
  1455. X        delta_time = old_sec;
  1456. X        delta_time = delta_time - (MAXSEC - alarm(0));
  1457. X        if (delta_time < 0L || delta_time > 32767L)
  1458. X            delta_time = 5L;
  1459. X        sec = delta_time;
  1460. X        alarm(sec);
  1461. X    }
  1462. X    sys_flag = !sys_flag;
  1463. X}
  1464. Xcmd_f()
  1465. X{
  1466. X    char            choice[6];
  1467. X    char           *file_ptr_x;
  1468. X    long            bytes_left;
  1469. X    int             result;
  1470. X    listed_l = FALSE;
  1471. X    listed_r = FALSE;
  1472. X    listed_n = FALSE;
  1473. X    if (first_time_in) {
  1474. X        result = atoi(l_f_base);
  1475. X        change_area(result);
  1476. X    }
  1477. X    first_time_in = FALSE;
  1478. Xffile:
  1479. X    portsout(CRLF);
  1480. X    portsout(CRLF);
  1481. X    signal(SIGALRM, timer);
  1482. X    signal(SIGHUP, hanged);
  1483. X    signal(SIGUSR1, mon_toggle);
  1484. X    signal(SIGUSR2, sys_toggle);
  1485. X    signal(SIGPIPE, chat);
  1486. X    signal(SIGINT, STOP);
  1487. X    cmd_t();
  1488. X    portsout("\n\rCurrent download area = ");
  1489. X    strcpy(buf128, f_pathname);
  1490. X    file_ptr_x = strrchr(buf128, '/');
  1491. X    *file_ptr_x = '\0';
  1492. X    file_ptr_x = strrchr(buf128, '/');
  1493. X    *file_ptr_x++;
  1494. X    strcpy(who_am_i, file_ptr_x);
  1495. X    portsout(who_am_i);
  1496. X    portsout("\n\rCurrent upload area = ");
  1497. X    strcpy(buf128, u_pathname);
  1498. X    file_ptr_x = strrchr(buf128, '/');
  1499. X    *file_ptr_x = '\0';
  1500. X    file_ptr_x = strrchr(buf128, '/');
  1501. X    *file_ptr_x++;
  1502. X    strcpy(who_am_i, file_ptr_x);
  1503. X    portsout(who_am_i);
  1504. X    portsout(CRLF);
  1505. X    bytes_left = max_dload - dload_total;
  1506. X    strcpy(buf128, "Allowable daily download limit = ");
  1507. X    sprintf(who_am_i, "%ld", bytes_left);
  1508. X    strcat(buf128, who_am_i);
  1509. X    strcat(buf128, " bytes\n\r");
  1510. X    portsout(buf128);
  1511. X    stop_that = FALSE;
  1512. X    bbsmenu(3,0);
  1513. X    portsin_cmp(choice, 5, "FfLlUuDdMmXxTtGgCcRrNnSsZz?");
  1514. X    portsout(CRLF);
  1515. X    fix_name(choice);
  1516. X    switch (choice[0]) {
  1517. X    case ('S'):
  1518. X        if (!privmsg(fpL))
  1519. X            goto ffile;
  1520. X        summary();
  1521. X        goto ffile;
  1522. X    case ('L'):
  1523. X        if (!privmsg(fpL))
  1524. X            goto ffile;
  1525. X        listed_r = FALSE;
  1526. X        listed_n = FALSE;
  1527. X        listed_l = FALSE;
  1528. X        file_loc( NULL );
  1529. X        goto ffile;
  1530. X    case ('F'):
  1531. X        if (!privmsg(fpL))
  1532. X            goto ffile;
  1533. X        listed_r = FALSE;
  1534. X        listed_n = FALSE;
  1535. X        file_l();
  1536. X        listed_l = TRUE;
  1537. X        goto ffile;
  1538. X    case ('N'):
  1539. X        if (!privmsg(fpL))
  1540. X            goto ffile;
  1541. X        listed_r = FALSE;
  1542. X        listed_l = FALSE;
  1543. X        file_n();
  1544. X        listed_n = TRUE;
  1545. X        goto ffile;
  1546. X    case ('Z'):
  1547. X        if (!privmsg(fpL))
  1548. X            goto ffile;
  1549. X        listed_r = FALSE;
  1550. X        listed_l = FALSE;
  1551. X        listed_n = FALSE;
  1552. X        allnew();
  1553. X        goto ffile;
  1554. X    case ('?'):        /* help */
  1555. X        if (!privmsg(mpZ))
  1556. X            goto ffile;
  1557. X        cmd_p(HELPFILE);
  1558. X        goto ffile;
  1559. X    case ('R'):
  1560. X        if (!privmsg(fpR))
  1561. X            goto ffile;
  1562. X        listed_l = FALSE;
  1563. X        listed_n = FALSE;
  1564. X        file_r();
  1565. X        listed_r = TRUE;
  1566. X        goto ffile;
  1567. X    case ('C'):
  1568. X        if (!privmsg(fpL))
  1569. X            goto ffile;
  1570. X        listed_l = FALSE;
  1571. X        listed_r = FALSE;
  1572. X        listed_n = FALSE;
  1573. X        file_c();
  1574. X        goto ffile;
  1575. X    case ('T'):
  1576. X        if (!privmsg(mpT))
  1577. X            goto ffile;
  1578. X        toggle = !toggle;
  1579. X        rewritx();
  1580. X        if (toggle) {
  1581. X            portsout("\n\rStop Mode\n\r");
  1582. X        } else {
  1583. X            portsout("\n\rContinuous Mode\n\r");
  1584. X        }
  1585. X        goto ffile;
  1586. X    case ('A'):
  1587. X        result = strlen(choice);
  1588. X        result--;
  1589. X        if (!result)
  1590. X            change_area(0);
  1591. X        else {
  1592. X            substr(choice, buf128, 2, result);
  1593. X            digit(buf128);
  1594. X            result = atoi(buf128);
  1595. X            change_area(result);
  1596. X        }
  1597. X        listed_r = FALSE;
  1598. X        listed_l = FALSE;
  1599. X        listed_n = FALSE;
  1600. X        goto ffile;
  1601. X    case ('X'):
  1602. X        if (!privmsg(mpX))
  1603. X            goto ffile;
  1604. X        cmd_x();
  1605. X        rewritx();
  1606. X        goto ffile;
  1607. X    case ('U'):
  1608. X        if (!privmsg(fpU))
  1609. X            goto ffile;
  1610. X        file_u();
  1611. X        listed_r = FALSE;
  1612. X        listed_l = FALSE;
  1613. X        listed_n = FALSE;
  1614. X        goto ffile;
  1615. X    case ('D'):
  1616. X        if (!privmsg(fpD))
  1617. X            goto ffile;
  1618. X        file_d();
  1619. X        goto ffile;
  1620. X    case ('M'):
  1621. X        if (!privmsg(fpM))
  1622. X            goto ffile;
  1623. X        listed_l = FALSE;
  1624. X        listed_r = FALSE;
  1625. X        listed_n = FALSE;
  1626. X        break;
  1627. X    case ('G'):
  1628. X        if (!privmsg(fpG))
  1629. X            goto ffile;
  1630. X        cmd_c();
  1631. X        break;
  1632. X    default:
  1633. X        goto ffile;
  1634. X    }
  1635. X}
  1636. Xfile_c()
  1637. X{
  1638. X    int             result, zcat;
  1639. X    char           *ptr, temp[16];
  1640. X    zcat = 0;
  1641. X    portsout("\n\r\n\rArchive Contents Listing Option for .tar(.Z), .zip  or .arc files\n\r\n\r");
  1642. X    portsout("Input archive file name to list ====> ");
  1643. X    portsin(x_filename, 15);
  1644. X    portsout(CRLF);
  1645. X    if (strlen(x_filename) < 1)
  1646. X        return;
  1647. X    strcpy(x_pathandfile, f_pathname);
  1648. X    strcat(x_pathandfile, x_filename);
  1649. X    ptr = strrchr(x_pathandfile, '.');
  1650. X    if (ptr == NULL) {
  1651. X        portsout("\n\rImproper file extension\n\r");
  1652. X        return;
  1653. X    }
  1654. X    *ptr++;
  1655. X    strcpy(temp, ptr);
  1656. X    if (strcmp(temp, "Z") == 0) {
  1657. X        zcat = 1;
  1658. X        strcpy(buf128, x_pathandfile);
  1659. X        ptr = strrchr(buf128, '.');
  1660. X        if (ptr == NULL) {
  1661. X            portsout("\n\rImproper file extension\n\r");
  1662. X            return;
  1663. X        }
  1664. X        *ptr = '\0';
  1665. X        ptr = strrchr(buf128, '.');
  1666. X        if (ptr == NULL) {
  1667. X            portsout("\n\rImproper file extension\n\r");
  1668. X            return;
  1669. X        }
  1670. X        *ptr++;
  1671. X        strcpy(temp, ptr);
  1672. X    }
  1673. X    if ((strcmp(temp, "arc") == 0) || (strcmp(temp, "ARC") == 0) || (strcmp(temp, "tar") == 0) || (strcmp(temp,"zip") == 0) || (strcmp(temp,"ZIP") ==0)) {
  1674. X        result = stat(x_pathandfile, &statbuf);
  1675. X        if (result != 0) {
  1676. X            portsout("\n\r\n\rThe requested file was not found!\n\r\n\r");
  1677. X            return;
  1678. X        }
  1679. X        if ((strcmp(temp, "arc") == 0 || strcmp(temp, "ARC") == 0)) {
  1680. X            listarc(x_pathandfile, port_id);
  1681. X/*
  1682. X            strcpy(buf128, ARC);
  1683. X            strcat(buf128, x_pathandfile);
  1684. X            strcat(buf128, " > ");
  1685. X            strcat(buf128, TMPFILE);
  1686. X            strcat(buf128, port_id);
  1687. X            (void) system(buf128);
  1688. X*/
  1689. X
  1690. X            strcpy(buf128, "/tmp/arclst.");
  1691. X            strcat(buf128, port_id);
  1692. X
  1693. X            portsout("\n\r\n\r");
  1694. X/*
  1695. X            strcpy(buf128, TMPFILE);
  1696. X            strcat(buf128, port_id);
  1697. X*/
  1698. X            cmd_p(buf128);
  1699. X            portsout("\n\r\n\r");
  1700. X            return;
  1701. X        }
  1702. X        if ((strcmp(temp, "zip") == 0 || strcmp(temp, "ZIP") == 0)) {
  1703. X
  1704. X            listzip( x_pathandfile, port_id);
  1705. X/*
  1706. X            strcpy(buf128, ZIP);
  1707. X            strcat(buf128, x_pathandfile);
  1708. X            strcat(buf128, " > ");
  1709. X            strcat(buf128, TMPFILE);
  1710. X            strcat(buf128, port_id);
  1711. X            (void) system(buf128);
  1712. X*/
  1713. X
  1714. X            strcpy(buf128, "/tmp/ziplst.");
  1715. X            strcat(buf128, port_id);
  1716. X
  1717. X            portsout("\n\r\n\r");
  1718. X/*
  1719. X            strcpy(buf128, TMPFILE);
  1720. X            strcat(buf128, port_id);
  1721. X*/
  1722. X            cmd_p(buf128);
  1723. X            portsout("\n\r\n\r");
  1724. X            return;
  1725. X        }
  1726. X        if (strcmp(temp, "tar") == 0) {
  1727. X            if (!zcat) {
  1728. X                strcpy(buf128, TAR);
  1729. X                strcat(buf128, x_pathandfile);
  1730. X            } else {
  1731. X                strcpy(buf128, ZCAT);
  1732. X                strcat(buf128, x_pathandfile);
  1733. X                strcat(buf128, " | ");
  1734. X                strcat(buf128, TAR);
  1735. X                strcat(buf128, "-");
  1736. X            }
  1737. X
  1738. X            strcat(buf128, " > ");
  1739. X            strcat(buf128, TMPFILE);
  1740. X            strcat(buf128, port_id);
  1741. X            portsout("\n\rOne moment please ....");
  1742. X            (void) system(buf128);
  1743. X            portsout("\n\r\n\r");
  1744. X            strcpy(buf128, TMPFILE);
  1745. X            strcat(buf128, port_id);
  1746. X            cmd_p(buf128);
  1747. X            portsout("\n\r\n\r");
  1748. X            return;
  1749. X        }
  1750. X    }
  1751. X    portsout("\n\r\n\rIllegal file extension!\n\r\n\r");
  1752. X}
  1753. Xfile_r()
  1754. X{
  1755. X    int             result;
  1756. X    if (!listed_r) {
  1757. X        portsout("\n\rOne moment please ....");
  1758. X        strcpy(buf128, "ls -l ");
  1759. X        strcat(buf128, f_pathname);
  1760. X        strcat(buf128, " > ");
  1761. X        strcat(buf128, TMPFILE);
  1762. X        strcat(buf128, port_id);
  1763. X        (void) system(buf128);
  1764. X    }
  1765. X    portsout("\n\r\n\r");
  1766. X    strcpy(buf128, TMPFILE);
  1767. X    strcat(buf128, port_id);
  1768. X    cmd_p(buf128);
  1769. X    portsout("\n\r\n\r");
  1770. X}
  1771. Xmsgck()
  1772. X{
  1773. X    portsout("A control-k will terminate the listing\n");
  1774. X}
  1775. Xfile_l()
  1776. X{
  1777. X    int             result;
  1778. X    int             zz;
  1779. X    char            timeptr[30];
  1780. X    char           *fileptr;
  1781. X    int             lnctx, xp;
  1782. X    lnctx = 1;
  1783. X    if (xpert)
  1784. X        xp = 10;
  1785. X    else
  1786. X        xp = 5;
  1787. X    xyy = atol(yy);
  1788. X    strcpy(buf128, f_pathname);
  1789. X    strcat(buf128, FILES);
  1790. X    if ((rdstatbuf = fopen(buf128, "r")) == NULL) {
  1791. X        portsout("\n\rThe are NO files available!\n\r");
  1792. X        return;
  1793. X    }
  1794. X    msgck();
  1795. X    portsout(CRLF);
  1796. X    strcpy(buf128, TMPFILE);
  1797. X    strcat(buf128, port_id);
  1798. X    while (fscanf(rdstatbuf, "%14s", x_filename) != EOF) {
  1799. X        zz = 0;
  1800. X        if (x_filename[0] == '~') {
  1801. X            goto finis;    /* Special case so that that
  1802. X                     * following files are not displayed
  1803. X                     * - can be used to disallow uploads
  1804. X                     * from being shown until they are
  1805. X                     * validated. */
  1806. X        }
  1807. X        if (x_filename[0] == '+') {
  1808. X            fileptr = x_filename + 1;
  1809. X            strcpy(work_msg, fileptr);
  1810. X            (void) fgets(buf128, 80, rdstatbuf);
  1811. X            strcat(work_msg, buf128);
  1812. X            strip(work_msg);
  1813. X            goto arond;
  1814. X        }
  1815. X        if (x_filename[0] == '.') {
  1816. X            strcpy(x_filename, "   ");
  1817. X            strcpy(who_am_i, "   ");
  1818. X            strcpy(who_am_I, "   ");
  1819. X            zz++;
  1820. X        }
  1821. X        if (result = fgets(buf128, 55, rdstatbuf) == NULL) {
  1822. X            if (!zz)
  1823. X                strcpy(buf128, " ***** No description on file *****");
  1824. X        }
  1825. X        strip(buf128);
  1826. X        if (!zz)
  1827. X            term_space(buf128);
  1828. X        result = strlen(buf128);
  1829. X        if (result == 0) {
  1830. X            if (!zz)
  1831. X                strcpy(buf128, " ***** No description on file *****");
  1832. X        }
  1833. X        if (!zz) {
  1834. X            strcpy(x_pathandfile, f_pathname);
  1835. X            strcat(x_pathandfile, x_filename);
  1836. X            result = stat(x_pathandfile, &statbuf);
  1837. X            if (result != 0) {
  1838. X                strcpy(who_am_i, "OFFLINE");
  1839. X                strcpy(who_am_I, "    ");
  1840. X                goto around;
  1841. X            }
  1842. X            xmm = statbuf.st_size;
  1843. X            sprintf(who_am_i, "%6ld", xmm);
  1844. X            xmm = statbuf.st_mtime;
  1845. X            strcpy(timeptr, ctime(&xmm));
  1846. X            substr(timeptr, bufx, 5, 6);
  1847. X            substr(timeptr, z_dd, 23, 2);
  1848. X            xmm = atol(z_dd);
  1849. X            if (xyy > xmm) {
  1850. X                substr(timeptr, bufx, 5, 3);
  1851. X                strcat(bufx, "-");
  1852. X                strcat(bufx, z_dd);
  1853. X            }
  1854. X            strcpy(who_am_I, bufx);
  1855. X        }
  1856. Xaround:
  1857. X        sprintf(work_msg, "%-15s%-7s%-6s%-50s", x_filename, who_am_i, who_am_I, buf128);
  1858. Xarond:
  1859. X        strip(work_msg);
  1860. X        term_space(work_msg);
  1861. X
  1862. X        sprintf(buf128, "%s\n\r", work_msg);
  1863. X        portsout(buf128);
  1864. X        if (stop_that) {
  1865. X            fclose(rdstatbuf);
  1866. X            stop_that = FALSE;
  1867. X            return;
  1868. X        }
  1869. X        if (toggle) {
  1870. X            lnctx++;
  1871. X            if (lnctx == 23) {
  1872. X                portsout(CRLF);
  1873. X                portsout("*** Depress a key to continue ( control-k to quit ) ........ ");
  1874. X                jnk[0] = portin();
  1875. X                if (jnk[0] == CTL_K || stop_that) {
  1876. X                    stop_that = FALSE;
  1877. X                    fclose(rdstatbuf);
  1878. X                    return;
  1879. X                }
  1880. X                portsout(CRLF);
  1881. X                lnctx = 1;
  1882. X            }
  1883. X        }
  1884. X    }
  1885. Xfinis:
  1886. X    fclose(rdstatbuf);
  1887. Xfinisl:
  1888. X    if (toggle && lnctx > xp) {
  1889. X        portsout(CRLF);
  1890. X        portsout("*** Depress a key to continue ........ ");
  1891. X        jnk[0] = portin();
  1892. X        portsout(CRLF);
  1893. X    }
  1894. X    portsout(CRLF);
  1895. X    portsout(CRLF);
  1896. X}
  1897. END_OF_FILE
  1898.   if test 39960 -ne `wc -c <'bbsc1.c.A'`; then
  1899.     echo shar: \"'bbsc1.c.A'\" unpacked with wrong size!
  1900.   elif test -f 'bbsc1.c.B'; then
  1901.     echo shar: Combining  \"'bbsc1.c'\" \(83594 characters\)
  1902.     cat 'bbsc1.c.A' 'bbsc1.c.B' > 'bbsc1.c'
  1903.     if test 83594 -ne `wc -c <'bbsc1.c'`; then
  1904.       echo shar: \"'bbsc1.c'\" combined with wrong size!
  1905.     else
  1906.       rm bbsc1.c.A bbsc1.c.B
  1907.     fi
  1908.   fi
  1909.   # end of 'bbsc1.c.A'
  1910. fi
  1911. if test -f 'checksum.c' -a "${1}" != "-c" ; then 
  1912.   echo shar: Will not clobber existing file \"'checksum.c'\"
  1913. else
  1914.   echo shar: Extracting \"'checksum.c'\" \(9680 characters\)
  1915.   sed "s/^X//" >'checksum.c' <<'END_OF_FILE'
  1916. X/*
  1917. X * A version of Ward Christensen's file transfer protocol for
  1918. X * Unix System V or 4.2 bsd.
  1919. X *
  1920. X *        Emmet P. Gray, ..!ihnp4!uiucuxc!fthood!egray, 16 Aug 85
  1921. X *
  1922. X * Modified by Sanford Zelkovitz   08/18/86
  1923. X * Last modification date: 05/20/87
  1924. X */
  1925. X
  1926. X#define SV
  1927. X#undef  BSD
  1928. X
  1929. X#include <stdio.h>
  1930. X#include <signal.h>
  1931. X#include <sys/types.h>
  1932. X#include <sys/stat.h>
  1933. X#ifdef SV
  1934. X#include <termio.h>
  1935. X#endif
  1936. X#ifdef BSD
  1937. X#include <sgtty.h>
  1938. X#endif
  1939. X
  1940. X#define MAXERRORS 10            /* max number of times to retry */
  1941. X#define SECSIZE    128            /* CP/M sector, transmission block */
  1942. X#define CPMEOF    26            /* End Of File (for CP/M) */
  1943. X#define SOH    1            /* Start Of Header */
  1944. X#define EOT    4            /* End Of Transmission */
  1945. X#define ACK    6            /* ACKnowledge */
  1946. X#define NAK    21            /* Negative AcKnowledge */
  1947. X#define CAN    24            /* CANcel */
  1948. X
  1949. Xint synchron;
  1950. Xint exit_return;
  1951. Xunsigned char crc1, crc2;
  1952. X#ifdef SV
  1953. Xstruct termio ttyhold;
  1954. X#endif
  1955. X#ifdef BSD
  1956. Xstruct sgttyb ttyhold;
  1957. X#endif
  1958. X
  1959. Xmain(argc, argv)
  1960. Xint argc;
  1961. Xchar *argv[];
  1962. X{
  1963. X    int msgstat;
  1964. X    char *tty, *ttyname();
  1965. X    struct stat stbuf;
  1966. X    exit_return=0;
  1967. X    if (argc != 3) {
  1968. X        usage();
  1969. X        exit(1);
  1970. X    }
  1971. X    tty = ttyname(1);
  1972. X    stat(tty, &stbuf); 
  1973. X    msgstat = (stbuf.st_mode & 0777);
  1974. X    chmod(tty, 0600);            /* mesg n */
  1975. X#ifdef SV
  1976. X    ioctl(0, TCGETA, &ttyhold);        /* get current settings */
  1977. X#endif
  1978. X#ifdef BSD
  1979. X    ioctl(0, TIOCGETP, &ttyhold);
  1980. X#endif
  1981. X    switch (*argv[1]) {
  1982. X        case 'r':
  1983. X            recvfile(argv[2]);
  1984. X            break;
  1985. X        case 's':
  1986. X            sendfile(argv[2]);
  1987. X            break;
  1988. X        default:
  1989. X            usage();
  1990. X    }
  1991. X#ifdef SV
  1992. X    ioctl(0, TCSETAF, &ttyhold);        /* restore settings */
  1993. X#endif
  1994. X#ifdef BSD
  1995. X    ioctl(0, TIOCSETP, &ttyhold);
  1996. X#endif
  1997. X    chmod(tty, msgstat);            /* restore mesg status */
  1998. X    exit(exit_return);
  1999. X}
  2000. X
  2001. X/* send a file to the remote */
  2002. Xsendfile(tfile)
  2003. Xchar *tfile;
  2004. X{
  2005. X    FILE *fp;
  2006. X    unsigned char chr, checksum, block, sector[SECSIZE];
  2007. X    int i, mode, nbytes, errcount, size, speed;
  2008. X    long min, sec;
  2009. X    static int baud[15] = {0, 50, 75, 110, 134, 150, 200,
  2010. X    300, 600, 1200, 1800, 2400, 4800, 9600, 19200};
  2011. X    struct stat sbuf;
  2012. X
  2013. X    if (!(fp = fopen(tfile, "r"))) {
  2014. X        fprintf(stderr, "xmodem: Can't open '%s' for read\r\n", tfile);
  2015. X        exit_return=1;
  2016. X        return;
  2017. X    }
  2018. X    stat(tfile, &sbuf);
  2019. X    size = (sbuf.st_size / 128) + 1;
  2020. X#ifdef SV
  2021. X    speed = baud[ttyhold.c_cflag & 017];
  2022. X#endif
  2023. X#ifdef BSD
  2024. X    speed = baud[ttyhold.sg_ispeed];
  2025. X#endif
  2026. X    sec = size;
  2027. X    sec = sec * 128L * 11L / speed;
  2028. X    min = sec / 60L;
  2029. X    sec = sec - min * 60L;
  2030. X    printf("File open: %d records\r\n", size);
  2031. X    printf("Send time: %ld min, %ld sec at %d baud\r\n", min, sec, speed);
  2032. X    printf("To cancel: use CTRL-X numerous times\r\n");
  2033. X    printf("Waiting ready signal\r\n");
  2034. X
  2035. X    rawmode();
  2036. X    errcount = 0;
  2037. X    mode = 0;
  2038. X    block = 1;
  2039. X    while (errcount < MAXERRORS) {
  2040. X        chr = getchar_t();
  2041. X        if (chr == NAK)            /* checksum mode */
  2042. X            break;
  2043. X        if (chr == 'C') {        /* CRC mode */
  2044. X            mode = 1;
  2045. X            break;
  2046. X        }
  2047. X        errcount++;
  2048. X    }
  2049. X    if (errcount == MAXERRORS) {
  2050. X        sleep(3);
  2051. X        fprintf(stderr, "xmodem: Timed out on acknowledge\r\n");
  2052. X        exit_return=1;
  2053. X        return;
  2054. X    }
  2055. X    while (nbytes = fread(sector, sizeof(sector[0]), SECSIZE, fp)) {
  2056. X        if (nbytes < SECSIZE) {        /* fill short sector */
  2057. X            for (i=nbytes; i < SECSIZE; i++)
  2058. X                sector[i] = CPMEOF;
  2059. X        }
  2060. X        errcount = 0;
  2061. X        while (errcount < MAXERRORS) {
  2062. X            putchar(SOH);        /* the header */
  2063. X            putchar(block);        /* the block number */
  2064. X            chr = ~block;
  2065. X            putchar(chr);        /* it's complement */
  2066. X            checksum = 0;
  2067. X            crc1 = 0;
  2068. X            crc2 = 0;
  2069. X            for (i=0; i < SECSIZE; i++) {
  2070. X                putchar(sector[i]);
  2071. X                if (mode)
  2072. X                    update_crc(sector[i]);
  2073. X                else
  2074. X                    checksum += sector[i];
  2075. X            }
  2076. X            if (mode) {
  2077. X                update_crc(0);
  2078. X                update_crc(0);
  2079. X                putchar(crc1);
  2080. X                putchar(crc2);
  2081. X            }
  2082. X            else
  2083. X                putchar(checksum);
  2084. Xrec_loop:
  2085. X            chr = getchar_t();
  2086. X            if (chr == CAN) {
  2087. X                sleep(3);
  2088. X                exit_return=1;
  2089. X                fprintf(stderr,"\r\nxmodem: Abort request received\r\n");
  2090. X                return;
  2091. X            }
  2092. X            if (chr == ACK)
  2093. X                break;        /* got it! */
  2094. X            if (chr != NAK) goto rec_loop;  /* Noise on line? */
  2095. X            errcount++;
  2096. X        }
  2097. X        if (errcount == MAXERRORS) {
  2098. X            error();
  2099. X            exit_return=1;
  2100. X            return;
  2101. X        }
  2102. X        block++;
  2103. X    }
  2104. X    errcount = 0;
  2105. X    exit_return=1;
  2106. X    while (errcount < MAXERRORS) {
  2107. X        putchar(EOT);
  2108. X        if (getchar_t() == ACK)
  2109. X            {
  2110. X            exit_return=0;
  2111. X            break;
  2112. X            }
  2113. X        errcount++;
  2114. X    }
  2115. X    return;
  2116. X}
  2117. X
  2118. X/* receive a file from the remote */
  2119. Xrecvfile(tfile)
  2120. Xchar *tfile;
  2121. X{
  2122. X    FILE *fp;
  2123. X    unsigned char hdr, blk, cblk, tmp, cksum;
  2124. X    unsigned char c1, c2, sum, block, sector[SECSIZE];
  2125. X    int i, stop = 0, mode, errcount, resync();
  2126. X    long true_end;
  2127. X    char ans[40];
  2128. X
  2129. X    if (!access(tfile, 00)) {
  2130. X        while (1) {
  2131. X            printf("File already exists \r\n");
  2132. X                return;
  2133. X        }
  2134. X    }
  2135. X
  2136. X    if (!(fp = fopen(tfile, "w"))) {
  2137. X        fprintf(stderr, "xmodem: Can't open '%s' for write\r\n", tfile);
  2138. X        return;
  2139. X    }
  2140. X    printf("File open - ready to receive\r\n");
  2141. X    rawmode();
  2142. X    errcount = 0;
  2143. X    block = 1;
  2144. X    
  2145. X    sleep(10);
  2146. X    while (errcount < MAXERRORS) {
  2147. X        if (errcount < (MAXERRORS / 2)) {
  2148. X            putchar(NAK);        /* try checksum mode first */
  2149. X            mode = 0;
  2150. X        }
  2151. X        else {
  2152. X            putchar('C');        /* then crc */
  2153. X            mode = 1;
  2154. X        }
  2155. X        if ((hdr = getchar_t()) == SOH) {
  2156. X            ungetc(SOH, stdin);
  2157. X            break;
  2158. X        }
  2159. X        errcount++;
  2160. X    }
  2161. X    if (errcount == MAXERRORS) {
  2162. X        sleep(3);
  2163. X        fprintf(stderr, "\r\nxmodem: Timed out on acknowledge\r\n");
  2164. X        return;
  2165. X    }
  2166. X    errcount = 0;
  2167. X
  2168. X    while (errcount < MAXERRORS) {
  2169. X        hdr = getchar_t();
  2170. X        if (hdr == CAN) {
  2171. X            sleep(3);
  2172. X            fprintf(stderr, "\r\nxmodem: Abort request received\r\n");
  2173. X            return;
  2174. X        }
  2175. X        if (hdr == EOT)            /* done! */
  2176. X            break;
  2177. X        if (hdr != SOH) {        /* read in junk for 6 seconds */
  2178. X            synchron = 0;        /*  to re-synchronized block */
  2179. X            signal(SIGALRM, resync);
  2180. X            alarm(6);
  2181. X            while(synchron == 0)
  2182. X                hdr = getchar();
  2183. X            goto nak;
  2184. X        }
  2185. X        blk = getchar_t();
  2186. X        cblk = getchar_t();
  2187. X        crc1 = 0;
  2188. X        crc2 = 0;
  2189. X        sum = 0;
  2190. X        for (i=0; i < SECSIZE; i++) {
  2191. X            sector[i] = getchar_t();
  2192. X            if (mode)
  2193. X                update_crc(sector[i]);
  2194. X            else
  2195. X                sum += sector[i];
  2196. X        }
  2197. X        if (mode) {
  2198. X            c1 = getchar_t();
  2199. X            c2 = getchar_t();
  2200. X        }
  2201. X        else
  2202. X            cksum = getchar_t();
  2203. X        if (blk != block && blk != (block - 1))
  2204. X            goto nak;
  2205. X        tmp = ~blk;
  2206. X        if (cblk != tmp)
  2207. X            goto nak;
  2208. X        if (mode) {
  2209. X            update_crc(0);
  2210. X            update_crc(0);
  2211. X            if (c1 != crc1 || c2 != crc2)
  2212. X                goto nak;
  2213. X        }
  2214. X        else {
  2215. X            if (cksum != sum)
  2216. X                goto nak;
  2217. X        }
  2218. X        if (block == blk) {
  2219. X            fflush(fp);
  2220. X            fwrite(sector, sizeof(sector[0]), SECSIZE, fp);
  2221. X        }
  2222. X        block = blk + 1;
  2223. X        putchar(ACK);            /* got it! */
  2224. X        errcount = 0;
  2225. X        continue;
  2226. X
  2227. X    nak:    putchar(NAK);            /* do it over */
  2228. X        errcount++;
  2229. X    }
  2230. X    if (errcount == MAXERRORS) {
  2231. X        error();
  2232. X        return;
  2233. X    }
  2234. X    putchar(ACK);
  2235. X    for (i = SECSIZE -1; i >= 0; i--) {    /* find true EOF */
  2236. X        if (sector[i] != CPMEOF) {
  2237. X            stop = i;
  2238. X            break;
  2239. X        }
  2240. X    }
  2241. X/*
  2242. X * Some CPM systems don't pad the end of the file with ^Z's so the file may
  2243. X * have junk at the end.  A conservative approach had to be taken in order
  2244. X * for Unix object code (where ^Z's may be valid data) to transfer properly.
  2245. X */
  2246. X    true_end = ftell(fp) - SECSIZE + stop +1;
  2247. X    fclose(fp);
  2248. X    truncate(tfile, true_end);
  2249. X    return;
  2250. X}
  2251. X
  2252. X/* give minimal usage message */
  2253. Xusage()
  2254. X{
  2255. X    fprintf(stderr, "Usage: xmodem [ s | r ] filename\r\n");
  2256. X    fprintf(stderr, "       options are 's' for send or 'r' for receive\r\n");
  2257. X    return;
  2258. X}
  2259. X
  2260. X/* exceeded the maximum number of retry's */
  2261. Xerror()
  2262. X{
  2263. X    putchar(CAN);
  2264. X    putchar(CAN);
  2265. X    putchar(CAN);
  2266. X    putchar(CAN);
  2267. X    sleep(3);
  2268. X    fprintf(stderr, "\r\nxmodem: Exceeded error limit...aborting\r\n");
  2269. X    return;
  2270. X}
  2271. X
  2272. X/* update the CRC bytes */
  2273. Xupdate_crc(c)
  2274. Xunsigned char c;
  2275. X{
  2276. X    int i, temp;
  2277. X    unsigned char carry, c_crc1, c_crc2;
  2278. X    for (i=0; i < 8; i++) {
  2279. X        temp = c * 2;
  2280. X        c = temp;            /* rotate left */
  2281. X        carry = ((temp > 255) ? 1 : 0);
  2282. X        temp = crc2 * 2;
  2283. X        crc2 = temp;
  2284. X        crc2 |= carry;            /* rotate with carry */
  2285. X        c_crc2 = ((temp > 255) ? 1 : 0);
  2286. X        temp = crc1 * 2;
  2287. X        crc1 = temp;
  2288. X        crc1 |= c_crc2;
  2289. X        c_crc1 = ((temp > 255) ? 1 : 0);
  2290. X        if (c_crc1) {
  2291. X            crc2 ^= 0x21;
  2292. X            crc1 ^= 0x10;
  2293. X        }
  2294. X    }
  2295. X    return;
  2296. X}
  2297. X
  2298. X/* getchar with a 10 sec time out */
  2299. Xgetchar_t()
  2300. X{
  2301. X    int force_it();
  2302. X    unsigned char c;
  2303. X    signal(SIGALRM, force_it);
  2304. X    alarm(10);                /* only have 10 sec... */
  2305. X    c = getchar();
  2306. X    alarm(0);
  2307. X    return(c);
  2308. X}
  2309. X
  2310. X/*
  2311. X * This code (and the resync() below) is the most machine dependent part
  2312. X * of the program.  The action of the signal SIGALRM during a read system
  2313. X * call is not well defined.  Some systems return the stack to the point
  2314. X * outside the system call, others inside the call itself.  Have fun...
  2315. X */
  2316. Xforce_it()
  2317. X{
  2318. X    unsigned char c;
  2319. X    c = CPMEOF;                /* arbitrary default char */
  2320. X#ifdef SV
  2321. X    ungetc(c, stdin);
  2322. X#endif
  2323. X#ifdef BSD
  2324. X    ioctl(0, TIOCSTI, &c);
  2325. X#endif
  2326. X    return;
  2327. X}
  2328. X
  2329. X/* truncate file to given length */
  2330. Xtruncate(path, length)
  2331. Xchar *path;
  2332. Xlong length;
  2333. X{
  2334. X    FILE *fp, *tempfp;
  2335. X    long i;
  2336. X    char c, string[80], *tempfile, *mktemp();
  2337. X    if (!(fp = fopen(path, "r"))) {
  2338. X        fprintf(stderr, "xmodem: Can't open '%s' for read\r\n", path);
  2339. X        return;
  2340. X    }
  2341. X    tempfile = mktemp("/tmp/trunXXXXXX");
  2342. X    if (!(tempfp = fopen(tempfile, "w"))) {
  2343. X        fprintf(stderr, "xmodem: Can't open temporary file\r\n");
  2344. X        return;
  2345. X    }
  2346. X    for (i=0; i < length; i++) {
  2347. X        c = fgetc(fp);
  2348. X        fputc(c, tempfp);
  2349. X    }
  2350. X    fclose(fp);
  2351. X    fclose(tempfp);
  2352. X    sprintf(string, "mv %s %s", tempfile, path);
  2353. X    system(string);
  2354. X    return;
  2355. X}
  2356. X
  2357. X/* put the stdin/stdout in the "raw" mode */
  2358. Xrawmode()
  2359. X{
  2360. X#ifdef SV
  2361. X    struct termio tbuf;
  2362. X    ioctl(0, TCGETA, &tbuf);
  2363. X    tbuf.c_cc[4] = 1;            /* VMIN */
  2364. X    tbuf.c_cc[5] = 0;            /* VTIME */
  2365. X    tbuf.c_iflag = 0;
  2366. X    tbuf.c_oflag = 0;
  2367. X    tbuf.c_lflag = 0;
  2368. X    tbuf.c_cflag &= ~CSIZE;
  2369. X    tbuf.c_cflag |= CS8;
  2370. X    tbuf.c_cflag &= ~PARENB;
  2371. X    ioctl(0, TCSETAF, &tbuf);
  2372. X    return;
  2373. X#endif
  2374. X#ifdef BSD
  2375. X    struct sgttyb sgbuf;
  2376. X    ioctl(0, TIOCGETP, &sgbuf);
  2377. X    sgbuf.sg_flags |= RAW;
  2378. X    sgbuf.sg_flags &= ~ECHO;
  2379. X    ioctl(0, TIOCSETP, &sgbuf);
  2380. X    return;
  2381. X#endif
  2382. X}
  2383. X
  2384. X/*  after 6 seconds of reading junk data... */
  2385. Xresync()
  2386. X{
  2387. X    char c;
  2388. X    synchron = 1;                /* set the flag */
  2389. X    c = SOH;
  2390. X#ifdef SV
  2391. X    ungetc(c, stdin);
  2392. X#endif
  2393. X#ifdef BSD
  2394. X    ioctl(0, TIOCSTI, &c);
  2395. X#endif
  2396. X    return;
  2397. X}
  2398. END_OF_FILE
  2399.   if test 9680 -ne `wc -c <'checksum.c'`; then
  2400.     echo shar: \"'checksum.c'\" unpacked with wrong size!
  2401.   fi
  2402.   # end of 'checksum.c'
  2403. fi
  2404. if test -f 'today/sun.c' -a "${1}" != "-c" ; then 
  2405.   echo shar: Will not clobber existing file \"'today/sun.c'\"
  2406. else
  2407.   echo shar: Extracting \"'today/sun.c'\" \(11105 characters\)
  2408.   sed "s/^X//" >'today/sun.c' <<'END_OF_FILE'
  2409. X/***** hpfcla:net.sources / nsc-pdc!rgb / 10:24 am  May 16, 1985
  2410. X*
  2411. X* Changed constants to Fort Collins, Colorado.  (ajs, 850520)
  2412. X* Made other minor output format improvements also.
  2413. X* 
  2414. X*        sun <options>
  2415. X*
  2416. X*        options:        -t hh:mm:ss    time (default is current system time)
  2417. X*             -d mm/dd/yy    date (default is current system date)
  2418. X*                        -a lat        decimal latitude (default = 45.5333)
  2419. X*                        -o lon        decimal longitude (default = 122.8333) 
  2420. X*             -z tz        timezone (default = 8, pst)
  2421. X*             -p        show position of sun (azimuth)
  2422. X*             -v        turn on debugging
  2423. X*        
  2424. X*        All output is to standard io.  
  2425. X*
  2426. X*     Compile with cc -O -o sun sun.c -lm
  2427. X*     Non 4.2 systems may have to change <sys/time.h> to <time.h> below.
  2428. X*    (yes, done)
  2429. X*
  2430. X*     Note that the latitude, longitude, time zone correction and
  2431. X*     time zone string are all defaulted in the global variable section.
  2432. X*
  2433. X*     Most of the code in this program is adapted from algorithms
  2434. X*     presented in "Practical Astronomy With Your Calculator" by
  2435. X*     Peter Duffet-Smith.
  2436. X*
  2437. X*     The GST and ALT-AZIMUTH algorithms are from Sky and Telescope,
  2438. X*     June, 1984 by Roger W. Sinnott
  2439. X*
  2440. X*     Author Robert Bond - Beaverton Oregon.
  2441. X*    
  2442. X*/
  2443. X
  2444. X#include <stdio.h>
  2445. X#include <math.h>
  2446. X#include <sys/types.h>
  2447. X#include <time.h>
  2448. X
  2449. X#define PI       3.141592654
  2450. X#define EPOCH     1980
  2451. X#define JDE     2444238.5    /* Julian date of EPOCH */
  2452. X
  2453. Xstatic double dtor();
  2454. Xstatic double adj360();
  2455. Xdouble adj24();
  2456. Xdouble julian_date();
  2457. Xdouble hms_to_dh();
  2458. Xdouble solar_lon();
  2459. Xdouble acos_deg();
  2460. Xdouble asin_deg();
  2461. Xdouble atan_q_deg();
  2462. Xdouble atan_deg();
  2463. Xdouble sin_deg();
  2464. Xdouble cos_deg();
  2465. Xdouble tan_deg();
  2466. Xdouble gmst();
  2467. X
  2468. Xlong time();
  2469. Xstruct tm *localtime();
  2470. X
  2471. Xint th;
  2472. Xint tm;
  2473. Xint ts;
  2474. Xint mo;
  2475. Xint day;
  2476. Xint yr;
  2477. Xint tz=8;            /* Default time zone */
  2478. Xchar *tzs  = "(PST)";        /* Default time zone string */
  2479. Xchar *dtzs = "(PDT)";        /* Default daylight savings time string */
  2480. Xint debug = 0;
  2481. Xint popt = 0;
  2482. X
  2483. Xdouble lat =  35.0000;        /* Default latitude (Fort Collins, Colorado) */
  2484. Xdouble lon = 118.0000;        /* Default Longitude (Degrees west) */ 
  2485. X
  2486. Xsun(sunrh, sunrm, sunsh, sunsm)
  2487. Xint *sunrh, *sunrm, *sunsh, *sunsm;
  2488. X{
  2489. X    double ed, jd;
  2490. X    double alpha1, delta1, alpha2, delta2, st1r, st1s, st2r, st2s;
  2491. X    double a1r, a1s, a2r, a2s, dt, dh, x, y;
  2492. X    double trise, tset, ar, as, alpha, delta, tri, da;
  2493. X    double lambda1, lambda2;
  2494. X    double alt, az, gst, m1;
  2495. X    double hsm, ratio;
  2496. X    time_t sec_1970;
  2497. X    int h, m;
  2498. X    struct tm *pt;
  2499. X
  2500. X    time(&sec_1970);
  2501. X    pt = localtime(&sec_1970);  
  2502. X
  2503. X    th = pt->tm_hour;
  2504. X    tm = pt->tm_min;
  2505. X    ts = pt->tm_sec;
  2506. X    yr = pt->tm_year + 1900;
  2507. X    mo = pt->tm_mon + 1;
  2508. X    day = pt->tm_mday;
  2509. X    if (pt->tm_isdst) {        /* convert tz to daylight savings time */
  2510. X    tz--;
  2511. X    tzs = dtzs;    
  2512. X    }
  2513. X
  2514. X
  2515. X    if (debug)
  2516. X        printf("Date: %d/%d/%d,  Time: %d:%d:%d, Tz: %d, Lat: %lf, Lon: %lf \n",
  2517. X        mo,day,yr,th,tm,ts,tz,lat,lon);
  2518. X
  2519. X    jd = julian_date(mo,day,yr);
  2520. X    ed = jd - JDE;
  2521. X
  2522. X    lambda1 = solar_lon(ed);
  2523. X    lambda2 = solar_lon(ed + 1.0);
  2524. X
  2525. X    lon_to_eq(lambda1, &alpha1, &delta1);
  2526. X    lon_to_eq(lambda2, &alpha2, &delta2);
  2527. X
  2528. X    rise_set(alpha1, delta1, &st1r, &st1s, &a1r, &a1s);
  2529. X    rise_set(alpha2, delta2, &st2r, &st2s, &a2r, &a2s);
  2530. X
  2531. X    m1 = adj24(gmst(jd - 0.5, 0.5 + tz / 24.0) - lon / 15); /* lst midnight */
  2532. X
  2533. X    if (debug)
  2534. X    printf ("local sidereal time of midnight is %lf \n", m1);
  2535. X
  2536. X    hsm = adj24(st1r - m1);
  2537. X
  2538. X    if (debug)
  2539. X    printf ("about %lf hours from midnight to dawn \n", hsm);
  2540. X
  2541. X    ratio = hsm / 24.07;
  2542. X
  2543. X    if (debug)
  2544. X    printf("%lf is how far dawn is into the day \n", ratio);
  2545. X
  2546. X    if (fabs(st2r - st1r) > 1.0) {
  2547. X    st2r += 24.0;
  2548. X    if (debug)
  2549. X        printf("st2r corrected from %lf to %lf \n", st2r-24.0, st2r);
  2550. X    }
  2551. X
  2552. X    trise = adj24((1.0 - ratio) * st1r + ratio * st2r);
  2553. X
  2554. X    hsm = adj24(st1s - m1);
  2555. X
  2556. X    if (debug)
  2557. X    printf ("about %lf hours from midnight to sunset \n", hsm);
  2558. X
  2559. X    ratio = hsm / 24.07;
  2560. X
  2561. X    if (debug)
  2562. X    printf("%lf is how far sunset is into the day \n", ratio);
  2563. X
  2564. X    if (fabs(st2s - st1s) > 1.0) {
  2565. X    st2s += 24.0;
  2566. X    if (debug)
  2567. X        printf("st2s corrected from %lf to %lf \n", st2s-24.0, st2s);
  2568. X    }
  2569. X
  2570. X    tset = adj24((1.0 - ratio) * st1s + ratio * st2s);
  2571. X
  2572. X    if (debug)
  2573. X    printf("Uncorrected rise = %lf, set = %lf \n", trise, tset);
  2574. X
  2575. X    ar = a1r * 360.0 / (360.0 + a1r - a2r);
  2576. X    as = a1s * 360.0 / (360.0 + a1s - a2s);
  2577. X
  2578. X    delta = (delta1 + delta2) / 2.0;
  2579. X    tri = acos_deg(sin_deg(lat)/cos_deg(delta));
  2580. X
  2581. X    x = 0.835608;        /* correction for refraction, parallax, ? */
  2582. X    y = asin_deg(sin_deg(x)/sin_deg(tri));
  2583. X    da = asin_deg(tan_deg(x)/tan_deg(tri));
  2584. X    dt = 240.0 * y / cos_deg(delta) / 3600;
  2585. X
  2586. X    if (debug)
  2587. X    printf("Corrections: dt = %lf, da = %lf \n", dt, da);
  2588. X
  2589. X    lst_to_hm(trise - dt, jd, &h, &m);
  2590. X    *sunrh = h;
  2591. X    *sunrm = m;
  2592. X
  2593. X    if (popt) {
  2594. X        dh_to_hm(ar - da, &h, &m);
  2595. X        printf("Azimuth: %3d %02d'\n", h, m);
  2596. X    }
  2597. X
  2598. X    lst_to_hm(tset + dt, jd, &h, &m);
  2599. X    *sunsh = h;
  2600. X    *sunsm = m;
  2601. X
  2602. X    if (popt) {
  2603. X        dh_to_hm(as + da, &h, &m);
  2604. X        printf("Azimuth: %3d %02d'\n", h, m);
  2605. X    } 
  2606. X     
  2607. X
  2608. X    if (popt) {
  2609. X
  2610. X    if (alpha1 < alpha2)
  2611. X        alpha = (alpha1 + alpha2) / 2.0;
  2612. X    else
  2613. X        alpha = (alpha1 + 24.0 + alpha2) / 2.0;
  2614. X    
  2615. X    if (alpha > 24.0)
  2616. X        alpha -= 24.0;
  2617. X
  2618. X    dh = (hms_to_dh(th, tm, ts) + tz) / 24.0;
  2619. X    if (dh > 0.5) {
  2620. X        dh -= 0.5;
  2621. X        jd += 0.5;
  2622. X    } else {
  2623. X        dh += 0.5;
  2624. X        jd -= 0.5;
  2625. X    }
  2626. X
  2627. X    gst = gmst(jd, dh);
  2628. X
  2629. X    eq_to_altaz(alpha, delta, gst, &alt, &az);
  2630. X
  2631. X    printf     ("The sun is at:   ");
  2632. X    dh_to_hm (az, &h, &m);
  2633. X    printf     ("Azimuth: %3d %02d'  ", h, m);
  2634. X    dh_to_hm (alt, &h, &m);
  2635. X    printf     ("Altitude: %3d %02d'\n", h, m);
  2636. X    }
  2637. X}
  2638. X
  2639. Xstatic double
  2640. Xdtor(deg)
  2641. Xdouble deg;
  2642. X{
  2643. X    return (deg * PI / 180.0);
  2644. X}
  2645. X
  2646. Xdouble
  2647. Xrtod(deg)
  2648. Xdouble deg;
  2649. X{
  2650. X    return (deg * 180.0 / PI);
  2651. X}
  2652. X
  2653. X
  2654. Xstatic double 
  2655. Xadj360(deg)
  2656. Xdouble deg;
  2657. X{
  2658. X    while (deg < 0.0) 
  2659. X    deg += 360.0;
  2660. X    while (deg > 360.0)
  2661. X    deg -= 360.0;
  2662. X    return(deg);
  2663. X}
  2664. X
  2665. Xdouble 
  2666. Xadj24(hrs)
  2667. Xdouble hrs;
  2668. X{
  2669. X    while (hrs < 0.0) 
  2670. X    hrs += 24.0;
  2671. X    while (hrs > 24.0)
  2672. X    hrs -= 24.0;
  2673. X    return(hrs);
  2674. X}
  2675. X
  2676. Xdouble 
  2677. Xjulian_date(m, d, y) int m, d, y;
  2678. X{
  2679. X    long a, b;
  2680. X    double jd;
  2681. X
  2682. X    if (m == 1 || m == 2) {
  2683. X    --y;
  2684. X    m += 12;
  2685. X    }
  2686. X    if (y < 1583) {
  2687. X    printf("Can't handle dates before 1583\n");
  2688. X    exit(1);
  2689. X    }
  2690. X    a = (long)y/100;
  2691. X    b = 2 - a + a/4;
  2692. X    b += (long)((double)y * 365.25);
  2693. X    b += (long)(30.6001 * ((double)m + 1.0));
  2694. X    jd = (double)d + (double)b + 1720994.5;
  2695. X
  2696. X    if (debug) 
  2697. X    printf("Julian date for %d/%d/%d is %lf \n", m, d, y, jd);
  2698. X
  2699. X    return(jd);
  2700. X}
  2701. X
  2702. Xdouble 
  2703. Xhms_to_dh(h, m, s) int h, m, s;
  2704. X{
  2705. X    double rv;
  2706. X    rv = h + m / 60.0 + s / 3600.0;
  2707. X
  2708. X    if (debug)
  2709. X    printf("For time %d:%d:%d frac hours are: %lf \n", h, m, s, rv);
  2710. X
  2711. X    return rv;
  2712. X}
  2713. X
  2714. Xdouble 
  2715. Xsolar_lon(ed)
  2716. Xdouble ed;
  2717. X{
  2718. X    double n, m, e, ect, errt, v;
  2719. X
  2720. X    n = 360.0 * ed / 365.2422;
  2721. X    n = adj360(n);
  2722. X    m = n + 278.83354 - 282.596403;
  2723. X    m = adj360(m);
  2724. X    m = dtor(m);
  2725. X    e = m; ect = 0.016718;
  2726. X    while ((errt = e - ect * sin(e) - m) > 0.0000001) 
  2727. X        e = e - errt / (1 - ect * cos(e));
  2728. X    v = 2 * atan(1.0168601 * tan(e/2));
  2729. X    v = adj360(v * 180.0 / PI + 282.596403);
  2730. X
  2731. X    if (debug)
  2732. X    printf("Solar Longitude for %lf days is %lf \n", ed, v); 
  2733. X
  2734. X    return(v);
  2735. X}
  2736. X
  2737. Xdouble 
  2738. Xacos_deg(x)
  2739. Xdouble x;
  2740. X{
  2741. X    return rtod(acos(x));
  2742. X}
  2743. X
  2744. Xdouble 
  2745. Xasin_deg(x)
  2746. Xdouble x;
  2747. X{
  2748. X    return rtod(asin(x));
  2749. X}
  2750. X
  2751. Xdouble 
  2752. Xatan_q_deg(y,x)
  2753. Xdouble y,x;
  2754. X{
  2755. X    double rv;
  2756. X
  2757. X    if (y == 0)
  2758. X        rv = 0;
  2759. X    else if (x == 0)
  2760. X        rv = y>0 ? 90.0 : -90.0;
  2761. X    else rv = atan_deg(y/x);
  2762. X
  2763. X    if (x<0) return rv+180.0;
  2764. X    if (y<0) return rv+360.0;
  2765. X    return(rv);
  2766. X}
  2767. X
  2768. Xdouble
  2769. Xatan_deg(x)
  2770. Xdouble x;
  2771. X{
  2772. X    return rtod(atan(x));
  2773. X}
  2774. X
  2775. Xdouble 
  2776. Xsin_deg(x)
  2777. Xdouble x;
  2778. X{
  2779. X    return sin(dtor(x));
  2780. X}
  2781. X
  2782. Xdouble 
  2783. Xcos_deg(x)
  2784. Xdouble x;
  2785. X{
  2786. X    return cos(dtor(x));
  2787. X}
  2788. X
  2789. Xdouble 
  2790. Xtan_deg(x)
  2791. Xdouble x;
  2792. X{
  2793. X    return tan(dtor(x));
  2794. X}
  2795. X
  2796. Xlon_to_eq(lambda, alpha, delta)
  2797. Xdouble lambda;
  2798. Xdouble *alpha;
  2799. Xdouble *delta;
  2800. X{
  2801. X    double tlam,epsilon;
  2802. X
  2803. X    tlam = dtor(lambda);
  2804. X    epsilon = dtor((double)23.441884);
  2805. X    *alpha = atan_q_deg((sin(tlam))*cos(epsilon),cos(tlam)) / 15.0;
  2806. X    *delta = asin_deg(sin(epsilon)*sin(tlam));
  2807. X
  2808. X    if (debug)
  2809. X    printf("Right ascension, declination for lon %lf is %lf, %lf \n",
  2810. X        lambda, *alpha, *delta);
  2811. X}
  2812. X
  2813. Xrise_set(alpha, delta, lstr, lsts, ar, as)
  2814. Xdouble alpha, delta, *lstr, *lsts, *ar, *as;
  2815. X{
  2816. X    double tar;
  2817. X    double h;
  2818. X
  2819. X    tar = sin_deg(delta)/cos_deg(lat);
  2820. X    if (tar < -1.0 || tar > 1.0) {
  2821. X    printf("The object is circumpolar\n");
  2822. X    exit (1);
  2823. X    }
  2824. X    *ar = acos_deg(tar);
  2825. X    *as = 360.0 - *ar;
  2826. X
  2827. X    h = acos_deg(-tan_deg(lat) * tan_deg(delta)) / 15.0;
  2828. X    *lstr = 24.0 + alpha - h;
  2829. X    if (*lstr > 24.0)
  2830. X    *lstr -= 24.0;
  2831. X    *lsts = alpha + h;
  2832. X    if (*lsts > 24.0)
  2833. X    *lsts -= 24.0;
  2834. X
  2835. X    if (debug) {
  2836. X    printf("For ra, decl. of %lf, %lf: \n", alpha, delta);
  2837. X    printf("lstr = %lf, lsts = %lf, \n", *lstr, *lsts);
  2838. X    printf("ar =   %lf, as =   %lf \n", *ar, *as);
  2839. X    }
  2840. X}
  2841. X
  2842. Xlst_to_hm(lst, jd, h, m)
  2843. Xdouble lst, jd;
  2844. Xint *h, *m;
  2845. X{
  2846. X    double ed, gst, jzjd, t, r, b, t0, gmt;
  2847. X
  2848. X    gst = lst + lon / 15.0;
  2849. X    if (gst > 24.0)
  2850. X    gst -= 24.0;
  2851. X    jzjd = julian_date(1,0,yr);
  2852. X    ed = jd-jzjd;
  2853. X    t = (jzjd -2415020.0)/36525.0;
  2854. X    r = 6.6460656+2400.05126*t+2.58E-05*t*t;
  2855. X    b = 24.0-(r-24.0*(yr-1900));
  2856. X    t0 = ed * 0.0657098 - b;
  2857. X    if (t0 < 0.0)
  2858. X    t0 += 24;
  2859. X    gmt = gst-t0;
  2860. X    if (gmt<0) 
  2861. X    gmt += 24.0;
  2862. X    gmt = gmt * 0.99727 - tz;;
  2863. X    if (gmt < 0)
  2864. X    gmt +=24.0;
  2865. X    dh_to_hm(gmt, h, m);
  2866. X}
  2867. X
  2868. Xdh_to_hm(dh, h, m)
  2869. Xdouble dh;
  2870. Xint *h, *m;
  2871. X{
  2872. X    double tempsec;
  2873. X
  2874. X    *h = dh;
  2875. X /* *m = (dh - *h) * 60; 
  2876. X    tempsec = (dh - *h) * 60 - *m; */
  2877. X    *m = fmod(dh, 1.0) * 60.0; 
  2878. X    tempsec = fmod(dh, 1.0) * 60.0 - *m;
  2879. X    tempsec = tempsec * 60 + 0.5;
  2880. X    if (tempsec > 30.0)
  2881. X    (*m)++;
  2882. X    if (*m == 60) {
  2883. X    *m = 0;
  2884. X    (*h)++;
  2885. X    }
  2886. X}
  2887. X
  2888. Xeq_to_altaz(r, d, t, alt, az)
  2889. Xdouble r, d, t;
  2890. Xdouble *alt, *az;
  2891. X{
  2892. X    double p = 3.14159265;
  2893. X    double r1 = p / 180.0;
  2894. X    double b = lat * r1;
  2895. X    double l = (360 - lon) * r1;
  2896. X    double t5, s1, c1, c2, s2, a, h;
  2897. X
  2898. X    if (debug)
  2899. X    printf("Given R. A. = %lf, DECL. = %lf, gmt = %lf \n", r, d, t);
  2900. X
  2901. X    r = r * 15.0 * r1;
  2902. X    d = d * r1;
  2903. X    t = t * 15.0 * r1;
  2904. X    t5 = t - r + l;
  2905. X    s1 = sin(b) * sin(d) + cos(b) * cos(d) * cos(t5);
  2906. X    c1 = 1 - s1 * s1;
  2907. X    if (c1 > 0) {
  2908. X    c1 = sqrt(c1);
  2909. X    h = atan(s1 / c1);
  2910. X    } else {
  2911. X    h = (s1 / fabs(s1)) * (p / 2.0);
  2912. X    }
  2913. X    c2 = cos(b) * sin(d) - sin(b) * cos(d) * cos(t5);
  2914. X    s2 = -cos(d) * sin(t5);
  2915. X    if (c2 == 0) 
  2916. X    a = (s2/fabs(s2)) * (p/2);
  2917. X    else {
  2918. X    a = atan(s2/c2);
  2919. X    if (c2 < 0)
  2920. X        a=a+p;
  2921. X    }
  2922. X    if (a<0)
  2923. X        a=a+2*p;
  2924. X    *alt = h / r1;
  2925. X    *az = a / r1;
  2926. X
  2927. X    if (debug)
  2928. X    printf("alt = %lf, az = %lf \n",*alt,*az);
  2929. X}
  2930. X
  2931. Xdouble
  2932. Xgmst(j, f)
  2933. Xdouble j,f;
  2934. X{
  2935. X    double d, j0, t, t1, t2, s;
  2936. X
  2937. X    d = j - 2451545.0;
  2938. X    t = d / 36525.0;
  2939. X    t1 = floor(t);
  2940. X    j0 = t1 * 36525.0 + 2451545.0;
  2941. X    t2 = (j - j0 + 0.5)/36525.0;
  2942. X    s = 24110.54841 + 184.812866 * t1; 
  2943. X    s += 8640184.812866 * t2;
  2944. X    s += 0.093104 * t * t;
  2945. X    s -= 0.0000062 * t * t * t;
  2946. X    s /= 86400.0;
  2947. X    s -= floor(s);
  2948. X    s = 24 * (s + (f - 0.5) * 1.002737909);
  2949. X    if (s < 0)
  2950. X    s += 24.0;
  2951. X    if (s > 24.0)
  2952. X    s -= 24.0;
  2953. X
  2954. X    if (debug)
  2955. X    printf("For jd = %lf, f = %lf, gst = %lf \n", j, f, s);
  2956. X
  2957. X    return(s);
  2958. X}
  2959. END_OF_FILE
  2960.   if test 11105 -ne `wc -c <'today/sun.c'`; then
  2961.     echo shar: \"'today/sun.c'\" unpacked with wrong size!
  2962.   fi
  2963.   # end of 'today/sun.c'
  2964. fi
  2965. echo shar: End of archive 4 \(of 11\).
  2966. cp /dev/null ark4isdone
  2967. MISSING=""
  2968. for I in 1 2 3 4 5 6 7 8 9 10 11 ; do
  2969.     if test ! -f ark${I}isdone ; then
  2970.     MISSING="${MISSING} ${I}"
  2971.     fi
  2972. done
  2973. if test "${MISSING}" = "" ; then
  2974.     echo You have unpacked all 11 archives.
  2975.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2976. else
  2977.     echo You still must unpack the following archives:
  2978.     echo "        " ${MISSING}
  2979. fi
  2980. exit 0
  2981. exit 0 # Just in case...
  2982.