home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sources / misc / 3910 < prev    next >
Encoding:
Text File  |  1992-09-08  |  65.1 KB  |  2,988 lines

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