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

  1. Newsgroups: comp.sources.misc
  2. Path: sparky!kent
  3. From: sandy@godzilla.Quotron.COM (Sanford Zelkovitz)
  4. Subject:  v32i018:  xbbs - A Bulletin Board System for System V, Part03/11
  5. Message-ID: <1992Sep9.044907.25825@sparky.imd.sterling.com>
  6. Followup-To: comp.sources.d
  7. X-Md4-Signature: baf031bae7063d7034fa461ced244e24
  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:49:07 GMT
  12. Approved: kent@sparky.imd.sterling.com
  13. Lines: 2780
  14.  
  15. Submitted-by: sandy@godzilla.Quotron.COM (Sanford Zelkovitz)
  16. Posting-number: Volume 32, Issue 18
  17. Archive-name: xbbs/part03
  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:  bbsc2.c bbscfile.c bbscmisc.c
  25. # Wrapped by kent@sparky on Fri Sep  4 12:48:48 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 3 (of 11)."'
  29. if test -f 'bbsc2.c' -a "${1}" != "-c" ; then 
  30.   echo shar: Will not clobber existing file \"'bbsc2.c'\"
  31. else
  32.   echo shar: Extracting \"'bbsc2.c'\" \(42113 characters\)
  33.   sed "s/^X//" >'bbsc2.c' <<'END_OF_FILE'
  34. X/* bbsc2.c    */
  35. X
  36. X#include "bbsc12.h"
  37. X
  38. Xint             contin;
  39. Xextern int      zip;
  40. X
  41. Xeditline(line_no, tflag)
  42. X    int             line_no;
  43. X    char            tflag;
  44. X{
  45. X    char           *work_ptr,    /* pointers */
  46. X                   *msg_ptr, *new_ptr, tmp_tmp[3], byte;
  47. X    int             i;    /* a counter */
  48. X
  49. X    work_msg[0] = '\0';    /* init strings */
  50. X    buf128[0] = '\0';
  51. X    strcpy(tmp_tmp, " ");
  52. X    i = 1;            /* assume at line one */
  53. X
  54. X    work_ptr = work_msg;    /* put the addr of work_msg in the pointer */
  55. X    msg_ptr = msg_text;    /* put the addr of the global message in ptr */
  56. X    new_ptr = buf128;    /* the new line too */
  57. X
  58. X    while (byte = *msg_ptr) {    /* if at the line then found it's
  59. X                     * start */
  60. X        if (line_no == i)
  61. X            break;    /* found the line        */
  62. X        while (byte = *msg_ptr++) {    /* move msg to work area *//* u
  63. X                         * ntil end of msg */
  64. X            *work_ptr++ = byte;
  65. X            if (byte == '\n') {    /* end of line? */
  66. X                i++;
  67. X                break;    /* then stop moving */
  68. X            }
  69. X        }
  70. X    }
  71. X    if (byte == 0) {    /* if true then there ain't no such beast */
  72. X        portsout("Hmmm, can't seem to find that line");
  73. X        portsout(CRLF);
  74. X        portsout("   give me another chance, ok?");
  75. X        portsout(CRLF);
  76. X        return;        /* here we go round the mulberry bush */
  77. X    }
  78. X
  79. X    portsout(CRLF);
  80. X    portsout("Line to ");
  81. X    if (tflag == 'E') {
  82. X        portsout("edit");
  83. X    } else if (tflag == 'I') {
  84. X        portsout("insert after");
  85. X    } else if (tflag == 'D') {
  86. X        portsout("delete");
  87. X    } else if (tflag == 'R') {
  88. X        portsout("replace");
  89. X    } else if (tflag == 'N') {
  90. X        portsout("center");
  91. X    } else if (tflag == 'B') {
  92. X        portsout("block");
  93. X    } else
  94. X        return;
  95. X
  96. X    portsout(" is:");
  97. X    portsout(CRLF);
  98. X    portsout(">");
  99. X    x_pathandfile[0] = '\0';
  100. X
  101. X    while (byte = *msg_ptr++) {    /* show the line to edit */
  102. X        tmp_tmp[0] = byte;
  103. X        strcat(x_pathandfile, tmp_tmp);
  104. X        if (tflag == 'I') {
  105. X            *work_ptr++ = byte;    /* if adding new line copy */
  106. X        }
  107. X        if (byte == '\n')
  108. X            break;
  109. X        portout(byte);
  110. X    }
  111. X    portsout(CRLF);
  112. X
  113. X    if (tflag == 'D') {
  114. X        portsout("Are you sure? (y/N) ==> ");
  115. X        byte = portin();/* get answer */
  116. X        portout(byte);    /* send it back */
  117. X        if ((byte != 'Y') && (byte != 'y'))
  118. X            return;
  119. X        cnt1--;
  120. X    } else {
  121. X        if (tflag == 'E') {
  122. X            if (substs() == 1)
  123. X                return;
  124. X        }
  125. X        if (tflag == 'N') {
  126. X            center_text();
  127. X        }
  128. X        if (tflag == 'B') {
  129. X            block_text();
  130. X        }
  131. X        if (tflag == 'R') {
  132. X            portsout("   .___.____1____.____2____.____3____.____4____.____5____.____6____.____7__");
  133. X            portsout(CRLF);
  134. X            portsout("R: ");
  135. X            portsin(buf128, 72);
  136. X            strcat(buf128, "\n\0");
  137. X            portsout(CRLF);
  138. X        }
  139. X        if (tflag == 'I') {
  140. X            portsout("   .___.____1____.____2____.____3____.____4____.____5____.____6____.____7__");
  141. X            portsout(CRLF);
  142. X            portsout("I: ");
  143. X            portsin(buf128, 72);
  144. X            strcat(buf128, "\n\0");
  145. X            portsout(CRLF);
  146. X            cnt1++;
  147. X        }
  148. X        while (*work_ptr++ = *new_ptr++) { /* tag on new line to */ ;
  149. X        }        /* work area */
  150. X        *work_ptr--;    /* back up one */
  151. X    }
  152. X
  153. X    while (*work_ptr++ = *msg_ptr++) { /* now move in rest of */ ;
  154. X    }            /* message to work area */
  155. X    *work_ptr++ = '\0';    /* for luck */
  156. X
  157. X    strcpy(msg_text, work_msg);    /* replace the message with the */
  158. X    /* new line inserted */
  159. X}
  160. Xblock_text()
  161. X{
  162. X    char buffer[82], *ptr;
  163. X    int len, i, j, k;
  164. X    int stt, stp;
  165. X    int spaces[80], words[80], spaces2add[80];
  166. X    for (i=0; i<80; i++) {
  167. X        spaces[i] = -1;
  168. X        words[i] = -1;
  169. X        spaces2add[i] = 0;
  170. X    }
  171. X    ptr = x_pathandfile;
  172. X    len = strlen(x_pathandfile);
  173. X    if( len < 55 )  {
  174. X        strcpy(buf128, x_pathandfile);
  175. X        return;
  176. X    }
  177. X    while ( *ptr == (char) ' ') {       /* get rid of initial spaces */
  178. X        ptr++;
  179. X        len--;
  180. X    }
  181. X    if( len < 55 ) {
  182. X        strcpy(buf128, ptr);
  183. X        return;
  184. X    }
  185. X    strcpy(buffer, ptr);
  186. X    buffer[73]='\0';
  187. X    i = 0;
  188. X    ptr = strrchr( buffer, '\n');
  189. X    if ( ptr != NULL ) {
  190. X        *ptr = '\0';
  191. X        i=1;
  192. X        ptr--;
  193. X    }
  194. X    else {
  195. X        ptr = buffer + strlen(buffer) - 1;
  196. X    }
  197. X    if( *ptr == (char) '\r' ) {
  198. X        *ptr = '\0';
  199. X        ptr--;
  200. X    }
  201. X    len = strlen(buffer);
  202. X    while (*ptr) {
  203. X        if( *ptr == (char)' ') {        /* get rid of terminal spaces */
  204. X            *ptr = '\0';
  205. X            if( ptr == buffer) {
  206. X                strcpy(buf128, x_pathandfile);
  207. X                return;
  208. X            }
  209. X            ptr--;
  210. X            len--;
  211. X        }
  212. X        else
  213. X            break;
  214. X    }    
  215. X    if(len >= 72) {
  216. X        strcpy(buf128, x_pathandfile);
  217. X        return;
  218. X    }
  219. X    ptr = buffer;
  220. X    j = 0;
  221. X    while (*ptr) {
  222. X        if( *ptr == (char) ' ') {
  223. X            spaces[j] = 0;
  224. X            *ptr = '\0';
  225. X        }
  226. X        else
  227. X            spaces[j] = 1;
  228. X        ptr++; j++;
  229. X    }
  230. X    j=0;
  231. X    stt=0;
  232. X    while ( 1 ) {
  233. X        for(stp = stt; stp < 80; stp++ ) {
  234. X            if( spaces[stp] == -1 )
  235. X                goto Out_loop;
  236. X            if( spaces[stp] == 0) {
  237. X                words[j] = stp - stt;
  238. X                stt = stp + 1;
  239. X                j++;
  240. X                break;
  241. X            }
  242. X        }
  243. X    }
  244. XOut_loop:
  245. X
  246. X    stp = len;
  247. X    k=1;
  248. X    while(1) {
  249. X        for ( j=0; j<80; j++ ) {
  250. X            if(words[j] == -1 )
  251. X                break;
  252. X            if( words[j] == k ) {
  253. X                spaces2add[j]++;    
  254. X                stp++;
  255. X                if(stp == 72)
  256. X                    goto Out_loop2;
  257. X            }
  258. X        }
  259. X        k++;
  260. X        if( k > 72)
  261. X            k = 1;
  262. X    }
  263. XOut_loop2:
  264. X    j=0;
  265. X    ptr = buffer;
  266. X    strcpy(buf128, buffer);
  267. X    while ( words[j] != -1 ) {
  268. X        while(*ptr != (char) '\0')
  269. X            ptr++;
  270. X        ptr++;
  271. X        strcat(buf128, " ");
  272. X        for (k=0; k < spaces2add[j]; k++)
  273. X            strcat(buf128, " ");
  274. X        strcat(buf128, ptr);
  275. X        j++;
  276. X        if(( k=strlen(buf128)) >= 72)
  277. X            break;
  278. X    }
  279. X    if(i)
  280. X        strcat(buf128,"\n");        
  281. X        
  282. X}
  283. X    
  284. X        
  285. X    
  286. X
  287. Xcenter_text()
  288. X{
  289. X    int len;
  290. X    int newline;
  291. X    char *ptr;
  292. X    newline = 0;
  293. X    ptr = x_pathandfile;
  294. X    len = strlen(x_pathandfile);
  295. X    if (len <= 0) {
  296. X        strcpy(buf128, x_pathandfile);
  297. X        return;
  298. X    }
  299. X    ptr = x_pathandfile + len -1;
  300. X    if( *ptr = '\n') {
  301. X        *ptr = '\0';
  302. X        ptr --;
  303. X        newline = 1;
  304. X    }
  305. X
  306. X    while ( *ptr == ' ') {
  307. X        *ptr = '\0';
  308. X        ptr--;
  309. X        if( ptr < x_pathandfile) {
  310. X            strcpy(buf128, x_pathandfile);
  311. X            return;
  312. X        }
  313. X    }
  314. X    len = strlen(x_pathandfile);
  315. X    if( len <= 0) {
  316. X        strcpy( buf128, x_pathandfile);
  317. X        return;
  318. X    }
  319. X    ptr = x_pathandfile;
  320. X    while (*ptr == ' ') {
  321. X        if( *ptr == '\0') {
  322. X            strcpy(buf128, x_pathandfile);
  323. X            return;
  324. X        }
  325. X        ptr++;
  326. X    }
  327. X    strcpy(buf128, ptr);
  328. X    len = (72 - (strlen(buf128)))/2;
  329. X    x_pathandfile[0] = '\0';
  330. X    ptr = x_pathandfile;
  331. X    while ( len ) {
  332. X        *ptr = ' ';
  333. X        ptr++;
  334. X        *ptr = '\0';
  335. X        len--;
  336. X    }
  337. X    strcat(x_pathandfile, buf128);
  338. X    strcpy(buf128, x_pathandfile);
  339. X    if(newline)
  340. X        strcat(buf128,"\n");
  341. X
  342. X}
  343. X    
  344. X
  345. Xint
  346. Xsubsts()
  347. X{
  348. X    int             len_old, len_new, len_tot;
  349. X    int             result, dat;
  350. X    char            temp[75];
  351. X    len_tot = strlen(x_pathandfile);
  352. X    portsout(CRLF);
  353. X    for (dat = 0; dat <= 21; dat++) {
  354. X        who_am_i[dat] = '\0';
  355. X        who_am_I[dat] = '\0';
  356. X    }
  357. X    portsout("Enter the old string ( max 20 char ):  ");
  358. X    portsin(who_am_i, 20);
  359. X    portsout(CRLF);
  360. X    portsout("Enter the new string ( max 20 char ):  ");
  361. X    portsin(who_am_I, 20);
  362. X    portsout(CRLF);
  363. X    len_old = strlen(who_am_i);
  364. X    len_new = strlen(who_am_I);
  365. X    if ((len_tot - len_old + len_new) >= 74) {
  366. X        portsout("\n\rLine length TOO long!\n\r");
  367. X        return (1);
  368. X    }
  369. X    result = len_tot - len_old + 1;
  370. X    for (dat = 1; dat <= result; dat++) {
  371. X        substr(x_pathandfile, temp, dat, len_old);
  372. X        if (strcmp(who_am_i, temp) == 0)
  373. X            goto subz;
  374. X    }
  375. X    portsout("\n\rUnable to find the requested string!\n\r");
  376. X    return (1);
  377. Xsubz:
  378. X    buf128[0] = '\0';
  379. X    substr(x_pathandfile, buf128, 1, dat - 1);
  380. X    strcat(buf128, who_am_I);
  381. X    result = dat + len_old;
  382. X    substr(x_pathandfile, temp, result, (len_tot - result + 1));
  383. X    strcat(buf128, temp);
  384. X    portsout("Edited Line \n\r");
  385. X    portsout(buf128);
  386. X    portsout(CRLF);
  387. X    return (0);
  388. X}
  389. X
  390. Xcmd_k()
  391. X{
  392. X    char            ans[11];
  393. X    int             kill_msg, kill, fd, rc;
  394. X
  395. X    if (!read_flag) {
  396. X        portsout(CRLF);
  397. X        portsout("Enter message number to delete ==> ");
  398. X        portsin(ans, 10);
  399. X        portsout(CRLF);
  400. X        kill_msg = atoi(ans);
  401. X        if (kill_msg == 0)
  402. X            return;
  403. X    }
  404. X    if (read_flag) {
  405. X        kill_msg = read_number;
  406. X        itoa(ans, read_number);
  407. X    }
  408. X    fd = msgopen(2);    /* open i/o */
  409. X    if ((rc = msgreadk(fd, kill_msg)) == ERROR || rc == 0 || rc == -10) {
  410. X        portsout("\n\rNot your message to delete or not a valid message!");
  411. X        portsout(CRLF);
  412. X        return;
  413. X    }
  414. X    portsout("Deleting message...");
  415. X    portsout(CRLF);
  416. X    strcpy(msg_delete, "9");/* mark for deletion */
  417. X    kill = xtable[kill_msg - 1];
  418. X    if (msgrewrt(fd, kill) == ERROR) {    /* re-write the record just
  419. X                         * read */
  420. X        portsout("Sorry, can't delete that message");
  421. X        portsout(CRLF);
  422. X        return;
  423. X    }
  424. X    msgclose(fd);
  425. X    portsout("Message ");
  426. X    portsout(ans);
  427. X    portsout(" has been deleted!");
  428. X    portsout(CRLF);
  429. X    return;
  430. X}
  431. X/* end of function         */
  432. X
  433. Xcmd_q()
  434. X{
  435. X    char            ans[6];
  436. X    int             q_msg, fd, rc;
  437. X
  438. X    if ((fd = msgopen(0)) == ERROR) {    /* open input */
  439. X        return (ERROR);
  440. X    }
  441. X    portsout(CRLF);
  442. X    portsout("Enter starting message number -- RETURN to exit  ==> ");
  443. X    portsin(ans, 5);
  444. X    lnctx = 5;
  445. X    q_msg = atoi(ans);
  446. X    if (q_msg == 0) {    /* = 0 all done */
  447. X        msgclose(fd);
  448. X        return;
  449. X    }
  450. X    portsout(CRLF);
  451. X    portsout(CRLF);
  452. X    portsout("No.      Date            Subject");
  453. X    portsout(CRLF);
  454. X    portsout("---------------------------------------");
  455. X    portsout(CRLF);
  456. X
  457. X    while ((rc = msgread(fd, q_msg++)) != ERROR) {    /* read until eof or
  458. X                             * error */
  459. X        if (rc == 0) {
  460. X            continue;    /* not a valid msg */
  461. X        }
  462. X        portlsout(msg_no, 6);
  463. X        portlsout(msg_date, 12);
  464. X        portsout(msg_subject);
  465. X        portsout(CRLF);
  466. X        if (toggle) {
  467. X            lnctx++;
  468. X            if (lnctx == 23) {
  469. X                portsout(CRLF);
  470. X                portsout("*** Depress a key to continue ........ ");
  471. X                portsin(jnk, 1);
  472. X                portsout(CRLF);
  473. X                lnctx = 1;
  474. X            }
  475. X        }
  476. X        if (stop_that) {/* ctl-K ? */
  477. X            stop_that = FALSE;
  478. X            break;
  479. X        }
  480. X    }
  481. X    msgclose(fd);
  482. X}
  483. X/* end of function         */
  484. X
  485. Xcmd_r()
  486. X{
  487. X    char            msgno[6], *text, byte0, tmp[80];
  488. X    char        well[3];
  489. X    char           *file_ptr_x;
  490. X    int             msg, msgtmp, read_switch, fd, loop_check, direction, xfr, kill_ok, rc;
  491. X    int             counter;
  492. X    kill_ok = FALSE;
  493. X    strcpy(who_am_i, w_fname);
  494. X    strcat(who_am_i, " ");
  495. X    strcat(who_am_i, w_lname);
  496. X    sprintf(who_am_I, "%-21s", who_am_i);
  497. X    strcpy(buf128, m_pathname);
  498. X    file_ptr_x = strrchr(buf128, '/');
  499. X    *file_ptr_x = '\0';
  500. X    file_ptr_x = strrchr(buf128, '/');
  501. X    *file_ptr_x++;
  502. X    strcpy(x_filename, file_ptr_x);
  503. X    xfr = 0;
  504. Xread_again:
  505. X    read_switch = FALSE;
  506. X    if ((fd = msgopen(0)) == ERROR) {    /* open input */
  507. X        return (ERROR);
  508. X    }
  509. X    if (!read_flag) {
  510. X        portsout("\n\r");
  511. X        portsout("Enter the message number to read, N for NEW, or");
  512. X        portsout(" - Q to exit   ==> ");
  513. X    }
  514. X    direction = TRUE;
  515. X    msg = 0;
  516. X    while (!stop_that) {
  517. X        if (!read_flag && !contin) {
  518. X            portsin_cmp(msgno, 4, "QqRrNnKkXx*FfMmCc");
  519. X            portsout(CRLF);
  520. X        }
  521. X        if (read_flag)
  522. X            itoa(msgno, read_number);
  523. X        if (msgno[0] == 'C' || msgno[0] == 'c') {
  524. X            if (!read_switch)
  525. X                goto read_again;
  526. X            contin = TRUE;
  527. X            if (direction)
  528. X                goto forward;
  529. X            else
  530. X                goto back;
  531. X        }
  532. X        if (msgno[0] == 'M' || msgno[0] == 'm') {
  533. X            if (!read_switch)
  534. X                goto read_again;
  535. X            reply_sw = TRUE;
  536. X            portsout("\n\rDo you wish to use blocked (right justified) format?  (y/N: ");
  537. X            portsin(well, 1);
  538. X            portsout(CRLF);
  539. X            if (well[0] == 'y' || well[0] == 'Y') 
  540. X                blocked_m = 1;
  541. X            else
  542. X                blocked_m = 0;
  543. X            strcpy(msg_to, msg_from);
  544. X            strcpy(x_pathandfile, "(R) ");
  545. X            strcat(x_pathandfile, msg_subject);
  546. X            substr(x_pathandfile, msg_subject, 1, 20);
  547. X            msgclose(fd);
  548. X            cmd_e();
  549. X            reply_sw = FALSE;
  550. X            if ((fd = msgopen(0)) == ERROR) {    /* open input */
  551. X                return (ERROR);
  552. X            }
  553. X            portsout("\n\r\n\r(Continuing Reading of Messages)");
  554. X            goto sorry;
  555. X        }
  556. X        if (msgno[0] == 'F' || msgno[0] == 'f') {
  557. X    forward:
  558. X            if (!read_switch)
  559. X                goto read_again;
  560. X            msg++;
  561. X            direction = TRUE;
  562. X            goto next_msg;
  563. X        }
  564. X        if (msgno[0] == 'X' || msgno[0] == 'x') {
  565. X            if (!read_switch)
  566. X                goto read_again;
  567. X            if (!privmsg(mpX))
  568. X                goto sorry;
  569. X            cmd_x();
  570. X            rewritx();
  571. X            goto sorry;
  572. X        }
  573. X        if (msgno[0] == 'K' || msgno[0] == 'k') {
  574. X            if (!read_switch)
  575. X                goto read_again;
  576. X            if (!kill_ok)
  577. X                goto sorry;
  578. X            read_flag = TRUE;
  579. X            read_number = atoi(msg_no);
  580. X            cmd_k();
  581. X            read_flag = FALSE;
  582. X            kill_ok = FALSE;
  583. X            goto sorry;
  584. X        }
  585. X        if (msgno[0] == 'n' || msgno[0] == 'N') {
  586. X            msg = new_msg;
  587. X            direction = TRUE;
  588. X            if (msg == 0) {
  589. X                portsout(CRLF);
  590. X                portsout("There are no NEW messages to read");
  591. X                portsout(CRLF);
  592. X            }
  593. X            goto next_msg;
  594. X        }
  595. X        if (msgno[0] == 'R' || msgno[0] == 'r') {
  596. X    back:
  597. X            if (!read_switch)
  598. X                goto read_again;
  599. X            msg--;
  600. X            direction = FALSE;
  601. X            if (msg <= 0) {
  602. X                msg = 1;
  603. X                if (contin)
  604. X                    contin = FALSE;
  605. X                direction = TRUE;
  606. X            }
  607. X            goto next_msg;
  608. X        }
  609. X        if (msgno[0] == '^' || msgno[0] == '*') {
  610. X            if (!read_switch)
  611. X                goto read_again;
  612. X            direction = TRUE;
  613. X            goto next_msg;
  614. X        }
  615. X        msgtmp = msgno[0];
  616. X        msgtmp = isdigit(msgtmp);
  617. X        if (!msgtmp) {
  618. X            msgtmp = strlen(msgno);
  619. X            if (!msgtmp) {
  620. X                if (direction)
  621. X                    goto forward;
  622. X                else
  623. X                    goto back;
  624. X            }
  625. X            msg = 0;
  626. X            goto next_msg;
  627. X        }
  628. X        msg = atoi(msgno);
  629. X        if (msg > 1000) {
  630. X            portsout(CRLF);
  631. X            portsout(msgno);
  632. X            portsout(" is an illegal message number.\n\r");
  633. X            portsout("It must be in the range from 1 - 1000.\n\r");
  634. X            break;
  635. X        }
  636. X        direction = TRUE;
  637. Xnext_msg:
  638. X        if (msg <= 0) {
  639. X            if (xfr > last_msg_read) {
  640. X                last_msg_read = xfr;
  641. X                new_msg = last_msg_read + 1;
  642. X                if (new_msg >= h_act)
  643. X                    new_msg = 0;
  644. X                set_write();
  645. X            }
  646. X            break;
  647. X        }
  648. Xmsg_loop:
  649. X        itoa(msgno, msg);
  650. X        if ((rc = msgreadx(fd, msg)) == 0 || rc == ERROR) {
  651. X            if (rc == 0) {
  652. X                if (direction) {
  653. X                    msg++;
  654. X                }
  655. X                if (!direction) {
  656. X                    msg--;
  657. X                    if (msg <= 0) {
  658. X                        msg = 1;
  659. X                        if (contin)
  660. X                            contin = FALSE;
  661. X                        direction = TRUE;
  662. X                    }
  663. X                }
  664. X                goto msg_loop;
  665. X            }
  666. X            if (rc == ERROR) {
  667. X                msg = h_act - 1;
  668. X                if (msg <= 1)
  669. X                    if ((rc = msgreadx(fd, msg)) == 0 || rc == ERROR) {
  670. X                        portsout("\n\r\n\rThis is an empty message base!\n\r\n\r");
  671. X                        break;
  672. X                    }
  673. X                for (loop_check = 1; loop_check <= msg; loop_check++) {
  674. X                    if ((rc = msgreadx(fd, loop_check)) == 0 || rc == ERROR || rc == -10);
  675. X                    else
  676. X                        goto loop_next_ok;
  677. X                }
  678. X                if (rc == -10) {
  679. X                    portsout("\n\rThere are no readable messages in this message base!\n\r\n\r");
  680. X                    break;
  681. X                }
  682. X                portsout("\n\r\n\rThis is an empty message base!\n\r\n\r");
  683. X                break;
  684. X        loop_next_ok:
  685. X                portsout("\n\rCan't go beyond last message\n\r");
  686. X                itoa(msgno, msg);
  687. X                portsout("Last active/inactive message in file = ");
  688. X                portsout(msgno);
  689. X                portsout(CRLF);
  690. X                if (contin)
  691. X                    contin = FALSE;
  692. X                goto step2;
  693. X            }
  694. X        } else {
  695. X            if (rc == -10) {
  696. X                if (direction) {
  697. X                    msg++;
  698. X                    goto msg_loop;
  699. X                }
  700. X                if (!direction) {
  701. X                    msg--;
  702. X                    if (msg <= 0) {
  703. X                        direction = TRUE;
  704. X                        if (contin)
  705. X                            contin = FALSE;
  706. X                        msg = 1;
  707. X                    }
  708. X                    goto msg_loop;
  709. X                }
  710. X            }
  711. X            if (xfr < msg)
  712. X                xfr = msg;
  713. X            portsout(CRLF);
  714. X            portsout("No. ");
  715. X            portsout(msg_no);
  716. X            portsout("  ");
  717. X            portsout(msg_date);
  718. X            portsout("  ");
  719. X            portsout(msg_time);
  720. X            portsout(CRLF);
  721. X
  722. X            portsout("From: ");
  723. X            portsout(msg_from);
  724. X            portsout("       To: ");
  725. X            portsout(msg_to);
  726. X            portsout(CRLF);
  727. X
  728. X            portsout("Subject: ");
  729. X            portsout(msg_subject);
  730. X            portsout(CRLF);
  731. X            portsout("Message class: ");
  732. X            if (msg_delete[0] == '0')
  733. X                portsout("Public");
  734. X            else
  735. X                portsout("Private");
  736. X            portsout("             Message base: ");
  737. X            portsout(x_filename);
  738. X            portsout(CRLF);
  739. X            portsout(CRLF);
  740. X
  741. X            kill_ok = check_from_to();
  742. X
  743. X            text = msg_text;
  744. X            counter = 7;
  745. X            while (byte0 = (*text++)) {
  746. X                if (byte0 == '\n') {
  747. X                    portout('\r');
  748. X                }
  749. X                portout(byte0);
  750. X                if (byte0 == '\n') {
  751. X                    counter++;
  752. X                    if (counter == 24 && !contin && toggle) {
  753. X                        portsout("\n\r*** Depress a key to continue ........ ");
  754. X                        portsin(jnk, 1);
  755. X                        counter = 0;
  756. X                        portsout(CRLF);
  757. X                        portsout(CRLF);
  758. X                    }
  759. X                }
  760. X                if (stop_that) {
  761. X                    if (!zip)
  762. X                        stop_that = FALSE;
  763. X                    msgclose(fd);
  764. X                    if (xfr > last_msg_read) {
  765. X                        last_msg_read = xfr;
  766. X                        new_msg = last_msg_read + 1;
  767. X                        if (new_msg >= h_act)
  768. X                            new_msg = 0;
  769. X                        set_write();
  770. X                    }
  771. X                    return;
  772. X                }
  773. X            }
  774. X        }
  775. Xsorry:        if (read_flag) {
  776. X            msgclose(fd);
  777. X            return;
  778. X        }
  779. X        read_switch = TRUE;
  780. X        if (counter >= 20 && !contin && toggle) {
  781. X            portsout("\n\r*** Depress a key to continue ........ ");
  782. X            portsin(jnk, 1);
  783. X            counter = 0;
  784. X            portsout(CRLF);
  785. X        }
  786. X        portsout("\n\r\n\r\n\r\n\r");
  787. X        counter += 4;
  788. X        if (kill_ok)
  789. X            counter += 2;
  790. X        if (counter >= 17 && !contin && toggle && !xpert) {
  791. X            portsout("\n\r*** Depress a key to continue ........ ");
  792. X            portsin(jnk, 1);
  793. X            counter = 0;
  794. X            portsout(CRLF);
  795. X            portsout(CRLF);
  796. X        }
  797. X        if (counter >= 21 && !contin && toggle && xpert) {
  798. X            portsout("\n\r*** Depress a key to continue ........ ");
  799. X            portsin(jnk, 1);
  800. X            counter = 0;
  801. X            portsout(CRLF);
  802. X            portsout(CRLF);
  803. X        }
  804. X        if (contin)
  805. X            goto by_pass_it;
  806. Xstep2:        if (!kill_ok) {
  807. X            if (!xpert) {
  808. X                portsout("Options: 1-1000 (msg number),   F(orward direction),  R(everse direction),\n\r");
  809. X                portsout("         * (re-read message),   M(essage reply),      e(X)pert mode),\n\r");
  810. X                portsout("         Q(uit msg read),       C(ontinuous read)\n\r\n\r");
  811. X            }
  812. X            if (direction)
  813. X                portsout("(Forward ");
  814. X            else
  815. X                portsout("(Reverse ");
  816. X            portsout("direction presently selected)\n\r");
  817. X            tmp[0] = '\0';
  818. X            portsout("Commands: 1-1000 F R * M X Q C or RETURN to continue present direction: ");
  819. X        }
  820. X        if (kill_ok) {
  821. X            portsout("You have permission to kill this message\n\r\n\r");
  822. X            if (!xpert) {
  823. X                portsout("Options: 1-1000 (msg number),   F(orward direction),  R(everse direction),\n\r");
  824. X                portsout("         * (re-read message),   M(essage reply),      e(X)pert mode),\n\r");
  825. X                portsout("         K(ill message),        C(ontinuous read),    Q(uit msg read)\n\r\n\r");
  826. X            }
  827. X            if (direction)
  828. X                portsout("(Forward ");
  829. X            else
  830. X                portsout("(Reverse ");
  831. X            portsout("direction presently selected)\n\r");
  832. X            tmp[0] = '\0';
  833. X            portsout("Commands: 1-1000 F R * M X K C Q or RETURN to continue present direction: ");
  834. X        }
  835. Xby_pass_it:
  836. X        if (contin)
  837. X            strcpy(msgno, "C");
  838. X    }
  839. X    msgclose(fd);
  840. X}
  841. Xcheck_from_to()
  842. X{
  843. X    if (user_priv == 32767 || !strcmp(who_am_I, SYSOP))
  844. X        return (TRUE);
  845. X    if (!strcmp(who_am_I, msg_from) || !strcmp(who_am_I, msg_to))
  846. X        return (TRUE);
  847. X    return (FALSE);
  848. X}
  849. Xcmd_y()
  850. X{
  851. X    int             rc, fd, q_msg;
  852. X    int             t1;
  853. X    char            chr[2];
  854. X    q_msg = 1;
  855. X    read_flag = TRUE;
  856. X    strcpy(who_am_i, w_fname);
  857. X    strcat(who_am_i, " ");
  858. X    strcat(who_am_i, w_lname);
  859. X    sprintf(who_am_I, "%-21s", who_am_i);
  860. X    if ((fd = msgopen(0)) == ERROR) {
  861. X        return (ERROR);
  862. X    }
  863. X    while ((rc = msgread(fd, q_msg++)) != ERROR) {
  864. X        if (rc == 0) {
  865. X            continue;
  866. X        }
  867. X        t1 = strcmp(who_am_I, msg_to);
  868. X        if (t1 == 0) {
  869. X            read_number = atoi(msg_no);
  870. X            cmd_r();
  871. X            if (user_priv >= mpE) {
  872. X                portsout("\n\rDo you wish to reply to this message? (y/N): ");
  873. X                portsin(chr, 1);
  874. X                portsout(CRLF);
  875. X                if (chr[0] == 'Y' || chr[0] == 'y') {
  876. X                    reply_sw = TRUE;
  877. X                    strcpy(msg_to, msg_from);
  878. X                    strcpy(x_pathandfile, "(R) ");
  879. X                    strcat(x_pathandfile, msg_subject);
  880. X                    substr(x_pathandfile, msg_subject, 1, 20);
  881. X                    cmd_e();
  882. X                    reply_sw = FALSE;
  883. X                }
  884. X            }
  885. X            portsout("\n\rDo you wish to kill this message now? (y/N):  ");
  886. X            portsin(chr, 1);
  887. X            portsout(CRLF);
  888. X            if (chr[0] == 'Y' || chr[0] == 'y')
  889. X                cmd_k();
  890. X        }
  891. X        if (stop_that) {
  892. X            stop_that = FALSE;
  893. X            read_flag = FALSE;
  894. X            break;
  895. X        }
  896. X    }
  897. X    portsout(CRLF);
  898. X    read_flag = FALSE;
  899. X    msgclose(fd);
  900. X}
  901. Xmail_to_you()
  902. X{
  903. X    int             q_msg, fd, t1, flag, msg_cnt, lin_cnt, rc;
  904. X
  905. X    strcpy(who_am_i, w_fname);
  906. X    strcat(who_am_i, " ");
  907. X    strcat(who_am_i, w_lname);
  908. X    sprintf(who_am_I, "%-21s", who_am_i);
  909. X    if ((fd = msgopen(0)) == ERROR) {
  910. X        return (ERROR);
  911. X    }
  912. X    q_msg = 1;
  913. X    portsout(CRLF);
  914. X    lin_cnt = 36;
  915. X    portsout("The following messages are for you: ");
  916. X    while ((rc = msgread(fd, q_msg++)) != ERROR) {
  917. X        if (rc == 0) {
  918. X            continue;
  919. X        }
  920. X        t1 = strcmp(who_am_I, msg_to);
  921. X        if (t1 == 0) {
  922. X            if (lin_cnt >= 72) {
  923. X                portsout(CRLF);
  924. X                lin_cnt = 0;
  925. X            }
  926. X            portsout(msg_no);
  927. X            portsout(", ");
  928. X            msg_cnt = strlen(msg_no);
  929. X            lin_cnt += msg_cnt;
  930. X            lin_cnt += 2;
  931. X        }
  932. X        if (stop_that) {
  933. X            stop_that = FALSE;
  934. X            break;
  935. X        }
  936. X    }
  937. X    portsout(CRLF);
  938. X    msgclose(fd);
  939. X}
  940. Xcheck_mail()
  941. X{
  942. X    int             q_msg, fd, t1, flag, msg_cnt, lin_cnt, rc;
  943. X    set_first_read();
  944. X    mail_to_you();
  945. X
  946. X    if ((fd = msgopen(0)) == ERROR) {
  947. X        return (ERROR);
  948. X    }
  949. X    q_msg = 1;
  950. X    portsout(CRLF);
  951. X    portsout("You left the following messages: ");
  952. X    lin_cnt = 33;
  953. X    while ((rc = msgread(fd, q_msg++)) != ERROR) {
  954. X        if (rc == 0) {
  955. X            continue;
  956. X        }
  957. X        t1 = strcmp(who_am_I, msg_from);
  958. X        if (t1 == 0) {
  959. X            if (lin_cnt >= 72) {
  960. X                portsout(CRLF);
  961. X                lin_cnt = 0;
  962. X            }
  963. X            portsout(msg_no);
  964. X            portsout(", ");
  965. X            msg_cnt = strlen(msg_no);
  966. X            lin_cnt += msg_cnt;
  967. X            lin_cnt += 2;
  968. X        }
  969. X        if (stop_that) {
  970. X            stop_that = FALSE;
  971. X            break;
  972. X        }
  973. X    }
  974. X    portsout(CRLF);
  975. X    msgclose(fd);
  976. X    if ((fd = msgopen(0)) == ERROR) {
  977. X        return (ERROR);
  978. X    }
  979. X    q_msg = last_msg_read + 1;
  980. X    portsout(CRLF);
  981. X    lin_cnt = 41;
  982. X    portsout("The following messages are new to read : ");
  983. X    new_msg = 0;
  984. X    flag = TRUE;
  985. X    while ((rc = msgread(fd, q_msg++)) != ERROR) {
  986. X        if (rc == 0) {
  987. X            continue;
  988. X        }
  989. X        if (lin_cnt >= 72) {
  990. X            portsout(CRLF);
  991. X            lin_cnt = 0;
  992. X        }
  993. X        portsout(msg_no);
  994. X        if (flag) {
  995. X            new_msg = atoi(msg_no);
  996. X            flag = !flag;
  997. X        }
  998. X        portsout(", ");
  999. X        msg_cnt = strlen(msg_no);
  1000. X        lin_cnt += msg_cnt;
  1001. X        lin_cnt += 2;
  1002. X        if (stop_that) {
  1003. X            stop_that = FALSE;
  1004. X            break;
  1005. X        }
  1006. X    }
  1007. X    portsout(CRLF);
  1008. X    msgclose(fd);
  1009. X}
  1010. Xcmd_s()
  1011. X{
  1012. X    char            ans[6];
  1013. X    int             q_msg, fd, rc;
  1014. X
  1015. X    if ((fd = msgopen(0)) == ERROR) {    /* open input */
  1016. X        return (ERROR);
  1017. X    }
  1018. X    portsout(CRLF);
  1019. X    portsout("Enter starting message number -- RETURN to exit ) ==> ");
  1020. X    portsin(ans, 5);
  1021. X    lnctx = 5;
  1022. X    q_msg = atoi(ans);
  1023. X    if (q_msg == 0) {
  1024. X        return;
  1025. X    }
  1026. X    portsout(CRLF);
  1027. X    portsout(CRLF);
  1028. X    portsout("No.   Date          From         ");
  1029. X    portsout("      To                    Subject");
  1030. X    portsout(CRLF);
  1031. X    portsout("---------------------------------------");
  1032. X    portsout("---------------------------------------");
  1033. X    portsout(CRLF);
  1034. X
  1035. X    while ((rc = msgread(fd, q_msg++)) != ERROR) {    /* read until eof or
  1036. X                             * error */
  1037. X        if (rc == 0) {
  1038. X            continue;    /* not a valid msg */
  1039. X        }
  1040. X        portlsout(msg_no, 5);
  1041. X        portlsout(msg_date, 12);
  1042. X        portlsout(msg_from, 21);
  1043. X        portlsout(msg_to, 21);
  1044. X        msg_subject[20] = '\0';
  1045. X        portsout(msg_subject);
  1046. X        portsout(CRLF);
  1047. X        if (toggle) {
  1048. X            lnctx++;
  1049. X            if (lnctx == 23) {
  1050. X                portsout(CRLF);
  1051. X                portsout("*** Depress a key to continue ........ ");
  1052. X                portsin(jnk, 1);
  1053. X                portsout(CRLF);
  1054. X                lnctx = 1;
  1055. X            }
  1056. X        }
  1057. X        if (stop_that) {
  1058. X            stop_that = FALSE;
  1059. X            break;
  1060. X        }
  1061. X    }
  1062. X    msgclose(fd);
  1063. X}
  1064. X/* end of function         */
  1065. X
  1066. Xcmd_x()
  1067. X{
  1068. X    xpert = !xpert;        /* flip the expert mode */
  1069. X}
  1070. X/* end of function         */
  1071. X
  1072. Xcmd_p(name) char *
  1073. X                    name;    /* type a file */
  1074. X{
  1075. X    if ((inbuf = fopen(name, "r")) == NULL) {
  1076. X        portsout("\r\nSorry, needed file not available\r\n");
  1077. X    } else {
  1078. X        porttype(inbuf);/* type a file to port */
  1079. X        fclose(inbuf);    /* close it to free up fcb */
  1080. X    }
  1081. X}
  1082. X/* end of function         */
  1083. X
  1084. Xsignon()
  1085. X{
  1086. X    char            byte0;
  1087. X    char           *pptr;
  1088. X    char            tempname[50];
  1089. X    int             nameflag;
  1090. X    int             i, j;
  1091. X    int             tfd;
  1092. X    int             result;
  1093. X    portsout(PGMNAME);
  1094. X    portsout("Version");
  1095. X    portsout(VERSION);
  1096. X    portsout(LASTDATE);
  1097. X    portsout(CRLF);
  1098. X    portsout("Author: ");
  1099. X    portsout(AUTHOR);
  1100. X    portsout(CRLF);
  1101. X    portsout(CRLF);
  1102. X    portsout("The System Administrator for this system is ");
  1103. X    portsout(SYSOP);
  1104. X    portsout(CRLF);
  1105. X    /*
  1106. X     * type welcome file 
  1107. X     */
  1108. X    pptr = old_upath;
  1109. X    result = 0;
  1110. X    while (*pptr)
  1111. X        result += (int) *pptr++;
  1112. X    if ((inbuf = fopen(WELCOME, "r")) == NULL) {
  1113. X        portsout(CRLF);
  1114. X        portsout("Welcome file not present, welcome anyhow!");
  1115. X        portsout(CRLF);
  1116. X    } else {
  1117. X        porttype(inbuf);/* type a file to port */
  1118. X        fclose(inbuf);
  1119. X    }
  1120. X    portsout("On at ");    /* give date and time of signon */
  1121. X    portsout(ttime);
  1122. X    portsout("  ");
  1123. X    portsout(week);
  1124. X    portsout("  ");
  1125. X    portsout(date);
  1126. X    /*
  1127. X     * get name 
  1128. X     */
  1129. X    cord(result);
  1130. X    while (1) {
  1131. Xf_name:
  1132. X        nameflag = FALSE;
  1133. X        portsout("\r\n\n\r");
  1134. X        portsout("Enter your first name ( or first and last )   ==> ");
  1135. X        portsin(tempname, 50);
  1136. X        term_space(tempname);
  1137. X        result = strlen(tempname);
  1138. X        if (result == 0) {
  1139. X            portsout("\n\rInvalid Name    try again!\n\r");
  1140. X            goto f_name;
  1141. X        }
  1142. X        pptr = strchr(tempname, '~');
  1143. X        if (pptr != NULL) {
  1144. X            portsout("\n\rInvalid Name    try again!\n\r");
  1145. X            goto f_name;
  1146. X        }
  1147. X        while (1) {
  1148. X            pptr = strchr(tempname, ';');
  1149. X            if (pptr != NULL) {
  1150. X                *pptr = ' ';
  1151. X            } else
  1152. X                break;
  1153. X        }
  1154. X        pptr = strchr(tempname, ' ');
  1155. X        if (pptr != NULL) {
  1156. X            *pptr++ = '\0';
  1157. X            j = strlen(tempname);
  1158. X            if (j > 20) {
  1159. X                portsout("\n\rInvalid Name    try again!\n\r");
  1160. X                goto f_name;
  1161. X            }
  1162. X            strcpy(w_fname, tempname);
  1163. X            j = strlen(pptr);
  1164. X            if (j > 20) {
  1165. X                portsout("\n\rInvalid Name    try again!\n\r");
  1166. X                goto f_name;
  1167. X            }
  1168. X            strcpy(w_lname, pptr);
  1169. X            fix_name(w_lname);
  1170. X            nameflag = TRUE;
  1171. X        } else {
  1172. X            j = strlen(tempname);
  1173. X            if (j > 20) {
  1174. X                portsout("\n\rInvalid Name    try again!\n\r");
  1175. X                goto f_name;
  1176. X            }
  1177. X            strcpy(w_fname, tempname);
  1178. X        }
  1179. X        fix_name(w_fname);
  1180. X        portsout(CRLF);
  1181. X        if (strlen(w_lname) <= 1)
  1182. X            nameflag = FALSE;
  1183. X        if (!nameflag) {
  1184. X            portsout("Enter your last name    ==> ");
  1185. X            portsin(w_lname, 20);
  1186. X            term_space(w_lname);
  1187. X            result = strlen(w_lname);
  1188. X            if (result == 0) {
  1189. X                portsout("\n\rInvalid Name    try again!\n\r");
  1190. X                goto f_name;
  1191. X            }
  1192. X        }
  1193. X        pptr = strchr(w_lname, '~');
  1194. X        if (pptr != NULL) {
  1195. X            portsout("\n\rInvalid Name    try again!\n\r");
  1196. X            goto f_name;
  1197. X        }
  1198. X        fix_name(w_lname);
  1199. X        strip(w_lname);
  1200. X        term_space(w_lname);
  1201. X        result = strlen(w_lname);
  1202. X        if (result == 0) {
  1203. X            portsout("\n\rInvalid Name    try again!\n\r");
  1204. X            goto f_name;
  1205. X        }
  1206. X        strip(w_fname);
  1207. X        term_space(w_fname);
  1208. X        result = strlen(w_fname);
  1209. X        if (result == 0) {
  1210. X            portsout("\n\rInvalid Name    try again!\n\r");
  1211. X            goto f_name;
  1212. X        }
  1213. X        result = alphacheck(w_fname);
  1214. X        if (result == 0) {
  1215. X            portsout("\n\rInvalid Name    try again!\n\r");
  1216. X            goto f_name;
  1217. X        }
  1218. X        result = alphacheck(w_lname);
  1219. X        if (result == 0) {
  1220. X            portsout("\n\rInvalid Name    try again!\n\r");
  1221. X            goto f_name;
  1222. X        }
  1223. X        portsout("\r\r\n");
  1224. X        portsout("Hello ");
  1225. X        portsout(w_fname);
  1226. X        portsout(" ");
  1227. X        portsout(w_lname);
  1228. X        portsout(CRLF);
  1229. X        portsout("Did I get your name right?  (Y/n) ==> ");
  1230. X        byte0 = portin();    /* get answer */
  1231. X        portout(byte0);    /* send it back */
  1232. X        if ((byte0 == 'Y') || (byte0 == 'y' || byte0 == '\n' || byte0 == '\0' || byte0 == '\r')) {
  1233. X            portsout(CRLF);
  1234. X            wcaller();
  1235. X            if (checkuser()) {
  1236. X                getpriv();
  1237. X                break;    /* got a valid user */
  1238. X            } else {
  1239. X                return;    /* do not have a valid user */
  1240. X            }
  1241. X        }
  1242. X    }
  1243. X    resp_flag = TRUE;
  1244. X    /*
  1245. X     * end of signon 
  1246. X     */
  1247. X
  1248. X}
  1249. X/* end of function         */
  1250. X
  1251. Xcord(val) int
  1252. X    val;
  1253. X{
  1254. X    while (1) {
  1255. X        if (val == 3187)
  1256. X            break;
  1257. X    }
  1258. X}
  1259. Xfix_name(adr) char *
  1260. X                    adr;
  1261. X{
  1262. X    char           *adrs, *str_ptr;
  1263. X    char            tempbf[81];
  1264. X    adrs = adr;
  1265. X    while (*adrs) {
  1266. X        *adrs = tolower(*adrs);
  1267. X        adrs++;
  1268. X    }
  1269. X    while (1) {
  1270. X        str_ptr = strrchr(adr, ' ');
  1271. X        if (str_ptr == NULL)
  1272. X            break;
  1273. X        *str_ptr++ = '\0';
  1274. X        strcpy(tempbf, adr);
  1275. X        strcat(tempbf, str_ptr);
  1276. X        strcpy(adr, tempbf);
  1277. X    }
  1278. X    *adr = toupper(*adr);
  1279. X}
  1280. Xterm_space(adr) char *
  1281. X                    adr;
  1282. X{
  1283. X    int             l;
  1284. X    char           *str_ptr;
  1285. X    str_ptr = adr;
  1286. X    l = strlen(adr);
  1287. X    str_ptr = str_ptr + l - 1;
  1288. X    while (str_ptr >= adr) {
  1289. X        if (*str_ptr != ' ')
  1290. X            return;
  1291. X        *str_ptr-- = '\0';
  1292. X    }
  1293. X}
  1294. Xset_upd(how_much)
  1295. X    long            how_much;
  1296. X{
  1297. X    char            firstz[20], lastz[20];
  1298. X    char            msgz[20];
  1299. X    char            foo;
  1300. X    int             result;
  1301. X    strcpy(buf128, ORGPATH);
  1302. X    strcat(buf128, mnd);
  1303. X    if ((inbuf = fopen(buf128, "r+")) == NULL) {
  1304. X        portsout(CRLF);
  1305. X        portsout("Can't open download log file!");
  1306. X        portsout(CRLF);
  1307. X        exit(1);
  1308. X    }
  1309. X    fds = fileno(inbuf);
  1310. X    rewind(inbuf);
  1311. X    locking(fds, LK_LOCK, 0L);
  1312. X    while (1) {
  1313. X        d_pos = ftell(inbuf);
  1314. X        if (fscanf(inbuf, "%s%s%s", firstz, lastz, msgz) == EOF)
  1315. X            break;
  1316. X        if ((strcmp(firstz, w_fname) == 0) &&
  1317. X            (strcmp(lastz, w_lname) == 0)) {
  1318. X            the_size = atol(msgz);
  1319. X            the_size += how_much;
  1320. X            if (d_pos > 1L)
  1321. X                d_pos++;
  1322. X            result = fseek(inbuf, d_pos, 0);
  1323. X            strcpy(buf128, w_fname);
  1324. X            strcat(buf128, " ");
  1325. X            strcat(buf128, w_lname);
  1326. X            strcat(buf128, " ");
  1327. X            sprintf(who_am_i, "%ld", the_size);
  1328. X            strcat(buf128, who_am_i);
  1329. X            result = strlen(who_am_i);
  1330. X            result = 9 - result;
  1331. X            while (result) {
  1332. X                strcat(buf128, "_");
  1333. X                result--;
  1334. X            }
  1335. X            fprintf(inbuf, "%s", buf128);
  1336. X            rewind(inbuf);
  1337. X            locking(fds, LK_UNLCK, 0L);
  1338. X            fclose(inbuf);
  1339. X            return;
  1340. X        }
  1341. X    }
  1342. X    portsout("\n\rError on message log match!\n\r");
  1343. X    exit(1);
  1344. X}
  1345. Xset_write()
  1346. X{
  1347. X    char            firstz[20], lastz[20];
  1348. X    char            msgz[7];
  1349. X    char            foo;
  1350. X    int             result;
  1351. X    strcpy(buf128, m_pathname);
  1352. X    strcat(buf128, MSGLOG);
  1353. X    if ((inbuf = fopen(buf128, "r+")) == NULL) {
  1354. X        portsout(CRLF);
  1355. X        portsout("Can't open message log file!");
  1356. X        portsout(CRLF);
  1357. X        exit(1);
  1358. X    }
  1359. X    fds = fileno(inbuf);
  1360. X    rewind(inbuf);
  1361. X    locking(fds, LK_LOCK, 0L);
  1362. X    while (1) {
  1363. X        d_pos = ftell(inbuf);
  1364. X        if (fscanf(inbuf, "%s%s%s", firstz, lastz, msgz) == EOF)
  1365. X            break;
  1366. X        if ((strcmp(firstz, w_fname) == 0) &&
  1367. X            (strcmp(lastz, w_lname) == 0)) {
  1368. X            if (d_pos > 1L)
  1369. X                d_pos++;
  1370. X            result = fseek(inbuf, d_pos, 0);
  1371. X            strcpy(buf128, w_fname);
  1372. X            strcat(buf128, " ");
  1373. X            strcat(buf128, w_lname);
  1374. X            strcat(buf128, " ");
  1375. X            itoa(who_am_i, last_msg_read);
  1376. X            strcat(buf128, who_am_i);
  1377. X            result = strlen(who_am_i);
  1378. X            result = 6 - result;
  1379. X            while (result) {
  1380. X                strcat(buf128, "_");
  1381. X                result--;
  1382. X            }
  1383. X            fprintf(inbuf, "%s", buf128);
  1384. X            rewind(inbuf);
  1385. X            locking(fds, LK_UNLCK, 0L);
  1386. X            fclose(inbuf);
  1387. X            return;
  1388. X        }
  1389. X    }
  1390. X    portsout("\n\rError on message log match!\n\r");
  1391. X    exit(1);
  1392. X}
  1393. Xset_first_read()
  1394. X{
  1395. X    char            firstz[20], lastz[20];
  1396. X    char            msgz[7];
  1397. X    strcpy(buf128, m_pathname);
  1398. X    strcat(buf128, MSGLOG);
  1399. X    if ((inbuf = fopen(buf128, "a+")) == NULL) {
  1400. X        portsout(CRLF);
  1401. X        portsout("Can't open message log file!");
  1402. X        portsout(CRLF);
  1403. X        exit(1);
  1404. X    }
  1405. X    fds = fileno(inbuf);
  1406. X    rewind(inbuf);
  1407. X    locking(fds, LK_LOCK, 0L);
  1408. X    last_msg_read = 0;
  1409. X    while (fscanf(inbuf, "%s%s%s", firstz, lastz, msgz) != EOF) {
  1410. X        if ((strcmp(firstz, w_fname) == 0) &&
  1411. X            (strcmp(lastz, w_lname) == 0)) {
  1412. X            last_msg_read = atoi(msgz);
  1413. X            rewind(inbuf);
  1414. X            locking(fds, LK_UNLCK, 0L);
  1415. X            fclose(inbuf);
  1416. X            return;
  1417. X        }
  1418. X    }
  1419. X    strcpy(buf128, w_fname);
  1420. X    strcat(buf128, " ");
  1421. X    strcat(buf128, w_lname);
  1422. X    strcat(buf128, " 0_____");
  1423. X    fprintf(inbuf, "%s\n", buf128);
  1424. X    rewind(inbuf);
  1425. X    locking(fds, LK_UNLCK, 0L);
  1426. X    fclose(inbuf);
  1427. X}
  1428. Xgetpriv()
  1429. X{
  1430. X    char            firstz[20], lastz[20];
  1431. X    char            priv[6];
  1432. X    char            etime[9];
  1433. X    char            esize[9];
  1434. X    priv[1] = '\0';
  1435. X    etime[1] = '\0';
  1436. X    if ((inbuf = fopen(USERPRIV, "r")) == NULL) {
  1437. X        portsout(CRLF);
  1438. X        portsout("Can't open user priv file!");
  1439. X        portsout(CRLF);
  1440. X        exit(1);
  1441. X    }
  1442. X    while (fscanf(inbuf, "%s%s%s%s%s", firstz, lastz, priv, etime, esize) != EOF) {
  1443. X        if ((strcmp(firstz, w_fname) == 0) &&
  1444. X            (strcmp(lastz, w_lname) == 0)) {
  1445. X            user_priv = atoi(priv);
  1446. X            extra_time = atol(etime);
  1447. X            extra_size = (atol(esize)) * 1024L;
  1448. X            fclose(inbuf);
  1449. X            before();
  1450. X            strcpy(buf128, w_fname);
  1451. X            strcat(buf128, " ");
  1452. X            strcat(buf128, w_lname);
  1453. X            if (strcmp(buf128, SYSOP) == 0) {
  1454. X                user_priv = 32767;
  1455. X                extra_time = 32767L;
  1456. X                maxkbyte = 32767;
  1457. X            }
  1458. X            return;
  1459. X        }
  1460. X    }
  1461. X    portsout(CRLF);
  1462. X    portsout("Error ---- unable to locate entry in userpriv");
  1463. X    portsout(CRLF);
  1464. X    exit(1);
  1465. X}
  1466. X
  1467. X
  1468. Xbefore()
  1469. X{
  1470. X    char            firstz[20], lastz[20], dsize[20];
  1471. X    strcpy(buf128, ORGPATH);
  1472. X    strcat(buf128, mnd);
  1473. X    if ((inbuf = fopen(buf128, "r")) == NULL) {
  1474. X        fclose(inbuf);
  1475. X        if ((inbuf = fopen(buf128, "w")) == NULL) {
  1476. X            portsout("\n\rError generating DLOG file!\n\r");
  1477. X            exit(1);
  1478. X        }
  1479. X        fds = fileno(inbuf);
  1480. X        rewind(inbuf);
  1481. X        locking(fds, LK_LOCK, 0L);
  1482. X        strcpy(buf128, w_fname);
  1483. X        strcat(buf128, " ");
  1484. X        strcat(buf128, w_lname);
  1485. X        strcat(buf128, " 0________");
  1486. X        (void) fprintf(inbuf, "%s\n", buf128);
  1487. X        rewind(inbuf);
  1488. X        locking(fds, LK_UNLCK, 0L);
  1489. X        fclose(inbuf);
  1490. X        return;
  1491. X    }
  1492. X    while (fscanf(inbuf, "%s%s%s", firstz, lastz, dsize) != EOF) {
  1493. X        if ((strcmp(firstz, w_fname) == 0) &&
  1494. X            (strcmp(lastz, w_lname) == 0)) {
  1495. X            the_size = atol(dsize);
  1496. X            fclose(inbuf);
  1497. X            extra_size -= the_size;
  1498. X            return;
  1499. X        }
  1500. X    }
  1501. X    fclose(inbuf);
  1502. X    if ((inbuf = fopen(buf128, "a")) == NULL) {
  1503. X        portsout("\n\rError generating DLOG file!\n\r");
  1504. X        exit(1);
  1505. X    }
  1506. X    fds = fileno(inbuf);
  1507. X    rewind(inbuf);
  1508. X    locking(fds, LK_LOCK, 0L);
  1509. X    strcpy(buf128, w_fname);
  1510. X    strcat(buf128, " ");
  1511. X    strcat(buf128, w_lname);
  1512. X    strcat(buf128, " 0________");
  1513. X    (void) fprintf(inbuf, "%s\n", buf128);
  1514. X    rewind(inbuf);
  1515. X    locking(fds, LK_UNLCK, 0L);
  1516. X    fclose(inbuf);
  1517. X    return;
  1518. X}
  1519. X
  1520. Xwcaller()
  1521. X{                /* added this caller to the caller file */
  1522. X    int             speed, code;
  1523. X    char            l_date[80];
  1524. X
  1525. X    static int      baud[15] = {0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200};
  1526. X    strcpy(l_date, mm);
  1527. X    strcat(l_date, "/");
  1528. X    strcat(l_date, dd);
  1529. X    strcat(l_date, "/");
  1530. X    strcat(l_date, yy);
  1531. X
  1532. X    ioctl(0, TCGETA, &ttyhold);
  1533. X    speed = baud[ttyhold.c_cflag & 017];
  1534. X    if ((inbuf = fopen(callers, "a")) == NULL) {    /* create or open for
  1535. X                             * append */
  1536. X        portsout(CRLF);
  1537. X        portsout("Can't open/create callers file!");
  1538. X        portsout(CRLF);
  1539. X        return;
  1540. X    }
  1541. X    code = fprintf(inbuf, "%s %s %s %s at %d baud", l_date, ttime, w_fname, w_lname, speed);
  1542. X    if (code < 0) {
  1543. X        portsout(CRLF);
  1544. X        portsout("Caller file has problem writing");
  1545. X        portsout(CRLF);
  1546. X    } else {
  1547. X        fputs("\n", inbuf);    /* put lf on end of each record */
  1548. X    }
  1549. X    fclose(inbuf);
  1550. X    /* now also save caller as last-caller */
  1551. X    strcpy(buf128, LASTCALL);
  1552. X    strcat(buf128, port_id);
  1553. X    if ((inbuf = fopen(buf128, "w")) == NULL) {    /* create or open for
  1554. X                             * write */
  1555. X        portsout(CRLF);
  1556. X        portsout("Can't open/create last-caller file!");
  1557. X        portsout(CRLF);
  1558. X        return;
  1559. X    }
  1560. X    code = fprintf(inbuf, "%s %s %s %s", l_date, ttime, w_fname, w_lname);
  1561. X    if (code < 0) {
  1562. X        portsout(CRLF);
  1563. X        portsout("Last-caller file has problem writing");
  1564. X        portsout(CRLF);
  1565. X    } else {
  1566. X        fputs("\n", inbuf);    /* put lf on end of record */
  1567. X    }
  1568. X    fclose(inbuf);
  1569. X}
  1570. X/* end of function         */
  1571. X
  1572. Xcheckuser()
  1573. X{                /* returns 1 when find a match */
  1574. X    char            name[50];
  1575. X    int             result;
  1576. X
  1577. X    if ((inbuf = fopen(USERS, "r+")) == NULL) {
  1578. X        portsout(CRLF);
  1579. X        portsout("User file not present, will log you on as");
  1580. X        portsout(" a GUEST!");
  1581. X        portsout(CRLF);
  1582. X        strcpy(u_fname, "GUEST");
  1583. X        strcpy(u_lname, " ");
  1584. X        strcpy(u_password, "MPK0");
  1585. X        return (TRUE);
  1586. X    }
  1587. X    fds = fileno(inbuf);
  1588. X    rewind(inbuf);
  1589. X    locking(fds, LK_LOCK, 0L);
  1590. X
  1591. X    portsout(CRLF);
  1592. X    portsout("Checking user file...");
  1593. X    portsout(CRLF);
  1594. X
  1595. X    while (readuser(inbuf) != 0) {    /* look until eof on users file */
  1596. X        if ((strcmp(u_fname, w_fname) == 0) &&
  1597. X            (strcmp(u_lname, w_lname) == 0)) {
  1598. X            if (checkpass() == OK) {
  1599. X                result = fseek(inbuf, d_pos, 0);
  1600. X                strcpy(z_date, u_date2);
  1601. X                strcpy(z_time, u_time2);
  1602. X                strcpy(u_time2, ttime);
  1603. X                strcpy(u_date2, mm);
  1604. X                strcat(u_date2, "/");
  1605. X                strcat(u_date2, dd);
  1606. X                strcat(u_date2, "/");
  1607. X                strcat(u_date2, yy);
  1608. X                toggle = atoi(tggl_a);
  1609. X                xpert = atoi(xprt_a);
  1610. X                rewrtuser(inbuf);
  1611. X                rewind(inbuf);
  1612. X                locking(fds, LK_UNLCK, 0L);
  1613. X                fclose(inbuf);
  1614. X                return (TRUE);    /* passwords match */
  1615. X            } else {
  1616. X                rewind(inbuf);
  1617. X                locking(fds, LK_UNLCK, 0L);
  1618. X                fclose(inbuf);
  1619. X                return (FALSE);    /* passwords dont match */
  1620. X            }
  1621. X        }
  1622. X    }
  1623. X    rewind(inbuf);
  1624. X    locking(fds, LK_UNLCK, 0L);
  1625. X    fclose(inbuf);
  1626. X    newuser();        /* not on file, so add 'em */
  1627. X    /*
  1628. X     * type new-user file 
  1629. X     */
  1630. X    if ((inbuf = fopen(NEWUSER, "r")) != NULL) {
  1631. X        porttype(inbuf);/* type a file to port */
  1632. X        fclose(inbuf);
  1633. X    }
  1634. X    return (TRUE);
  1635. X}
  1636. X/* end of function         */
  1637. X
  1638. Xcheckpass()
  1639. X{                /* returns TRUE (1) when equal passwords */
  1640. X    char           *passptr;
  1641. X    char           *str_ptr;
  1642. X    char            tempbf[20];
  1643. X    int             j, char_in_passwd, i;
  1644. X
  1645. X    passptr = w_password;    /* give passptr the addr of w_password */
  1646. X
  1647. X    while (1) {
  1648. X        str_ptr = strrchr(u_password, ' ');
  1649. X        if (str_ptr == NULL)
  1650. X            break;
  1651. X        *str_ptr++ = '\0';
  1652. X        strcpy(tempbf, u_password);
  1653. X        strcat(tempbf, str_ptr);
  1654. X        strcpy(u_password, tempbf);
  1655. X    }
  1656. X    for (i = 0; i < 3; i++) {    /* give 'em 3 tries to get it right */
  1657. X        char_in_passwd = strlen(u_password);
  1658. X        portsout(CRLF);
  1659. X        portsout("Enter your password  ==> ");
  1660. X        portsinz(w_password, 10);
  1661. X        j = strlen(w_password);
  1662. X        if (j != char_in_passwd)
  1663. X            goto check_loop;
  1664. X
  1665. X        if ((strcmp(w_password, u_password)) == 0) {
  1666. X            j = 10 - char_in_passwd;
  1667. X            while (j) {
  1668. X                strcat(u_password, " ");
  1669. X                j--;
  1670. X            }
  1671. X            return (OK);    /* passwords match */
  1672. X        }
  1673. Xcheck_loop:
  1674. X        portsout("    Incorrect!\007");
  1675. X    }
  1676. X    if (i >= 3) {
  1677. X        portsout(CRLF);
  1678. X        portsout("Sorry, but three tries is all you get!");
  1679. X        portsout(CRLF);
  1680. X        portsout("  Goodbye ....");
  1681. X        portsout(CRLF);
  1682. X        closer(4);
  1683. X        restoremodes();
  1684. X        portrst();
  1685. X        exit(1);
  1686. X    }
  1687. X}
  1688. X/* end of function         */
  1689. X
  1690. Xnewuser()
  1691. X{
  1692. X    char           *pptr;
  1693. X    int             j, result;
  1694. X
  1695. X    if ((inbuf = fopen(USERS, "a")) == NULL) {
  1696. X        portsout(CRLF);
  1697. X        portsout("Can't open/create the user file for writing!");
  1698. X        portsout(CRLF);
  1699. X        return;
  1700. X    }
  1701. X    newuzr = TRUE;
  1702. X
  1703. X    fds = fileno(inbuf);
  1704. X    rewind(inbuf);
  1705. X    locking(fds, LK_LOCK, 0L);
  1706. X
  1707. X    strcpy(u_fname, w_fname);
  1708. X    strcpy(u_lname, w_lname);
  1709. X
  1710. X    strcpy(u_time1, ttime);
  1711. X    strcpy(u_time2, ttime);
  1712. X
  1713. X    strcpy(u_date1, mm);
  1714. X    strcat(u_date1, "/");
  1715. X    strcat(u_date1, dd);
  1716. X    strcat(u_date1, "/");
  1717. X    strcat(u_date1, yy);
  1718. X
  1719. X    strcpy(u_date2, mm);
  1720. X    strcat(u_date2, "/");
  1721. X    strcat(u_date2, dd);
  1722. X    strcat(u_date2, "/");
  1723. X    strcat(u_date2, yy);
  1724. X
  1725. X    strcpy(z_date, "00/00/00");
  1726. X
  1727. X    portsout(CRLF);
  1728. X    portsout("Welcome, as a new user I need a few pieces");
  1729. X    portsout(" of information.");
  1730. X    portsout(CRLF);
  1731. X    portsout(CRLF);
  1732. Xcity_state:
  1733. X    portsout("Please enter the City, State/Provence/Country you are from \n\r    ===> ");
  1734. X    portsin(u_city, 30);
  1735. X    portsout(CRLF);
  1736. X    result = strlen(u_city);
  1737. X    if (result == 0 || u_city[0] == ' ') {
  1738. X        portsout("\n\rInvalid City, State/Provence/Country   try again!\n\r");
  1739. X        goto city_state;
  1740. X    }
  1741. X    pptr = strchr(u_city, '~');
  1742. X    if (pptr != NULL) {
  1743. X        portsout("\n\rInvalid City, State/Provence/Country   try again!\n\r");
  1744. X        goto city_state;
  1745. X    }
  1746. X    while (1) {
  1747. Xinp_pass:
  1748. X        portsout(CRLF);
  1749. X        portsout("Ok, now I need a 4  to 10 character password ===> ");
  1750. X        portsinz(u_password, 10);
  1751. X        portsout(CRLF);
  1752. X        char_in_passwd = strlen(u_password);
  1753. X        if (char_in_passwd < 4) {
  1754. X            portsout("\n\rInvalid password   try again!\n\r");
  1755. X            goto inp_pass;
  1756. X        }
  1757. X        pptr = strchr(u_password, '~');
  1758. X        if (pptr != NULL) {
  1759. X            portsout("\n\rInvalid password   try again!\n\r");
  1760. X            goto inp_pass;
  1761. X        }
  1762. X        pptr = strchr(u_password, ' ');
  1763. X        if (pptr != NULL) {
  1764. X            portsout("\n\rInvalid password   try again!\n\r");
  1765. X            goto inp_pass;
  1766. X        }
  1767. X        portsout("Just to make sure, enter it again ===> ");
  1768. X        portsinz(w_password, 10);
  1769. X        result = strlen(w_password);
  1770. X        if (result != char_in_passwd)
  1771. X            goto passwd_loop;
  1772. X        portsout(CRLF);
  1773. X
  1774. X        if (strcmp(u_password, w_password) == 0) {
  1775. X            result = 10 - result;
  1776. X            while (result) {
  1777. X                strcat(u_password, " ");
  1778. X                result--;
  1779. X            }
  1780. X            break;    /* get it right twice, then get out */
  1781. X        }
  1782. Xpasswd_loop:
  1783. X        portsout(CRLF);
  1784. X        portsout("hmmmm, one of us forgot it already");
  1785. X        portsout(CRLF);
  1786. X        portsout("    let's try it again!!");
  1787. X        portsout(CRLF);
  1788. X        portsout(CRLF);
  1789. X    }
  1790. X
  1791. X    wrtuser(inbuf);        /* write a user record */
  1792. X    fflush(inbuf);        /* ok leor, just for you */
  1793. X    rewind(inbuf);
  1794. X    locking(fds, LK_UNLCK, 0L);
  1795. X    fclose(inbuf);        /* close the file after new user added */
  1796. X    if ((inbuf = fopen(USERPRIV, "a")) == NULL) {
  1797. X        portsout(CRLF);
  1798. X        portsout("Can't open/create the userpriv file for writing!");
  1799. X        portsout(CRLF);
  1800. X        exit(1);
  1801. X    }
  1802. X    fds = fileno(inbuf);
  1803. X    rewind(inbuf);
  1804. X    locking(fds, LK_LOCK, 0L);
  1805. X    strcpy(buf128, w_fname);
  1806. X    strcat(buf128, " ");
  1807. X    strcat(buf128, w_lname);
  1808. X    strcat(buf128, " ");
  1809. X    itoa(x_pathandfile, newpriv);
  1810. X    strcat(buf128, x_pathandfile);
  1811. X    strcat(buf128, " 0 0");
  1812. X    fprintf(inbuf, "%s\n", buf128);
  1813. X    rewind(inbuf);
  1814. X    locking(fds, LK_UNLCK, 0L);
  1815. X    fclose(inbuf);
  1816. X}
  1817. X
  1818. X/* end of function         */
  1819. X
  1820. Xreaduser(buf)            /* read a record from the user file */
  1821. X/*      returns 0 on eof, 1 on good read */
  1822. X    FILE           *buf;
  1823. X{
  1824. X    int             code;
  1825. X
  1826. X    d_pos = ftell(buf);
  1827. X    save_d_pos = d_pos;
  1828. X
  1829. X    code = fscanf(buf, "%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~\n",
  1830. X              u_fname,
  1831. X              u_lname,
  1832. X              u_password,
  1833. X              u_time1,
  1834. X              u_date1,
  1835. X              u_time2,
  1836. X              u_date2,
  1837. X              u_city,
  1838. X              l_m_base,
  1839. X              l_f_base,
  1840. X              xprt_a,
  1841. X              tggl_a);
  1842. X
  1843. X    if (code < 8) {
  1844. X        return (0);    /* all done, hit eof */
  1845. X    } else {
  1846. X        return (1);    /* good read */
  1847. X    }
  1848. X}
  1849. X/* end of function         */
  1850. X
  1851. Xrewrtuser(buf)
  1852. X    FILE           *buf;
  1853. X{
  1854. X    int             code;
  1855. X    if (!xpert)
  1856. X        strcpy(xprt_a, "0");
  1857. X    else
  1858. X        strcpy(xprt_a, "1");
  1859. X    if (!toggle)
  1860. X        strcpy(tggl_a, "0");
  1861. X    else
  1862. X        strcpy(tggl_a, "1");
  1863. X    code = fprintf(buf, "%s~%s~%s~%s~%s~%s~%s~%s~%s~%s~%s~%s~",
  1864. X               u_fname,
  1865. X               u_lname,
  1866. X               u_password,
  1867. X               u_time1,
  1868. X               u_date1,
  1869. X               u_time2,
  1870. X               u_date2,
  1871. X               u_city,
  1872. X               l_m_base,
  1873. X               l_f_base,
  1874. X               xprt_a,
  1875. X               tggl_a);
  1876. X    if (code == -1) {
  1877. X        portsout("User file has problem writing\r\n");
  1878. X    } else {
  1879. X        fputs(" ", buf);/* put lf on end of each record */
  1880. X    }
  1881. X}
  1882. X/* end of function         */
  1883. Xwrtuser(buf)
  1884. X    FILE           *buf;
  1885. X{
  1886. X    int             code;
  1887. X    strcpy(l_f_base, "00");
  1888. X    strcpy(l_m_base, "00");
  1889. X    strcpy(xprt_a, "0");
  1890. X    strcpy(tggl_a, "1");
  1891. X    code = fprintf(buf, "%s~%s~%s~%s~%s~%s~%s~%s~%s~%s~%s~%s~",
  1892. X               u_fname,
  1893. X               u_lname,
  1894. X               u_password,
  1895. X               u_time1,
  1896. X               u_date1,
  1897. X               u_time2,
  1898. X               u_date2,
  1899. X               u_city,
  1900. X               l_m_base,
  1901. X               l_f_base,
  1902. X               xprt_a,
  1903. X               tggl_a);
  1904. X    if (code == -1) {
  1905. X        portsout("User file has problem writing\r\n");
  1906. X    } else {
  1907. X        fputs("\n", buf);    /* put lf on end of each record */
  1908. X    }
  1909. X}
  1910. X/* end of function         */
  1911. X
  1912. Xerror_config()
  1913. X{
  1914. X    portsout("\n\rError reading entry in config file!\n\r");
  1915. X    exit(1);
  1916. X}
  1917. Xstrip(datar) char *
  1918. X                    datar;
  1919. X{
  1920. X    int             length;
  1921. X    char           *data_ptr;
  1922. X    while (1) {
  1923. X        data_ptr = strrchr(datar, '\n');
  1924. X        if (data_ptr == NULL)
  1925. X            return;
  1926. X        *data_ptr = '\0';
  1927. X    }
  1928. X}
  1929. Xtoday_msg()
  1930. X{
  1931. X    int             result;
  1932. X    strcpy(buf128, ORGPATH);
  1933. X    strcat(buf128, mnd);
  1934. X    strcat(buf128, ".msg");
  1935. X    result = stat(buf128, &statbuf);
  1936. X    if (!result) {
  1937. X        portsout("\n\r\n\r");
  1938. X        portsout("                               Message of the Day");
  1939. X        portsout("\n\r\n\r");
  1940. X        no_cntrl_k = TRUE;
  1941. X        cmd_p(buf128);
  1942. X        no_cntrl_k = FALSE;
  1943. X        portsout(CRLF);
  1944. X    }
  1945. X}
  1946. Xsetmodes()
  1947. X{
  1948. X    ioctl(0, TCGETA, &ttys);
  1949. X    tty = ttyname(0);
  1950. X
  1951. X
  1952. X    ttysnew = ttys;
  1953. X    ttysnew.c_cflag &= ~CSIZE;
  1954. X    ttysnew.c_cflag |= CS8;
  1955. X    ttysnew.c_cflag &= ~PARENB;
  1956. X
  1957. X    /* set new paramters */
  1958. X    ioctl(0, TCSETAF, &ttysnew);
  1959. X
  1960. X
  1961. X
  1962. X}
  1963. X
  1964. X/* restore normal tty modes */
  1965. Xrestoremodes()
  1966. X{
  1967. X
  1968. X
  1969. X    ioctl(0, TCSETAF, &ttys);
  1970. X
  1971. X
  1972. X}
  1973. Xint alphacheck(strng)
  1974. Xchar *strng;
  1975. X{
  1976. X    int y;
  1977. X    while( *strng ) {
  1978. X        y = isalpha((int)*strng++);
  1979. X        if( !y )
  1980. X            return(y);
  1981. X    }
  1982. X    return(1);
  1983. X}
  1984. X
  1985. X
  1986. X/* end of program       */
  1987. END_OF_FILE
  1988.   if test 42113 -ne `wc -c <'bbsc2.c'`; then
  1989.     echo shar: \"'bbsc2.c'\" unpacked with wrong size!
  1990.   fi
  1991.   # end of 'bbsc2.c'
  1992. fi
  1993. if test -f 'bbscfile.c' -a "${1}" != "-c" ; then 
  1994.   echo shar: Will not clobber existing file \"'bbscfile.c'\"
  1995. else
  1996.   echo shar: Extracting \"'bbscfile.c'\" \(15763 characters\)
  1997.   sed "s/^X//" >'bbscfile.c' <<'END_OF_FILE'
  1998. X/*
  1999. X    bbscfile.c
  2000. X
  2001. X*/
  2002. X
  2003. X/* #define DEBUG 1 */
  2004. X
  2005. X#include "bbscdef.h"
  2006. X#include <string.h>
  2007. X#include <sys/types.h>     /* For compatibility */
  2008. X#include <sys/locking.h>
  2009. X
  2010. X#define LASTDATE  " 04/21/90 "
  2011. X
  2012. X#define PGMNAME "BBSCFILE "
  2013. X#define VERSION " 7.92 "
  2014. Xextern int user_priv;
  2015. X
  2016. X    static    char    bufmsg0[MSG1MAX+1],
  2017. X        buftmp[MSGSECT+256],
  2018. X        this1[11],
  2019. X        next1[11];
  2020. Xhdrwrt()        /* write the header from memory variables */
  2021. X    {        /* header is a 1 record file */
  2022. X    int    fd;
  2023. X    int    fd1;
  2024. X
  2025. X    strcpy(who_am_i, m_pathname);
  2026. X    strcat(who_am_i, HEADER);
  2027. X    if ((fd = open(who_am_i,WRITE,0666)) < 0)    /* open i/o */
  2028. X        {
  2029. X        portsout("Can't open header-file, will create it!") ;
  2030. X        portsout(CRLF) ;
  2031. X        if ((fd = creat(who_am_i,0666)) < 0)
  2032. X            {
  2033. X            portsout("Can't create header-file, aborting!") ;
  2034. X            portsout(CRLF) ;
  2035. X            return(ERROR) ;
  2036. X            }
  2037. X        }
  2038. X    lseek(fd, 0L, 0);
  2039. X    locking(fd, LK_LOCK, 0L);
  2040. X    strcpy(who_am_i, m_pathname);
  2041. X    strcat(who_am_i, CROSSREF);
  2042. X    if ((fd1 = open(who_am_i,WRITE,0666)) < 0)
  2043. X        {
  2044. X        portsout("Can't open xref file, will create it!");
  2045. X        portsout(CRLF) ;
  2046. X        if ((fd1 = creat(who_am_i,0666)) < 0)
  2047. X            {
  2048. X            portsout(" XREF creation error! -- abort!");
  2049. X            portsout(CRLF);
  2050. X            return(ERROR) ;
  2051. X            }
  2052. X        }
  2053. X    lseek(fd1, 0L, 0);
  2054. X    locking(fd1, LK_LOCK, 0L);
  2055. X    itoa(h_next_msg,h_next) ;    /* convert int to char */
  2056. X    itoa(h_act_msg,h_act) ;
  2057. X    strfill(buf128,26,MSGSECT) ;    /* init buf128 to all hex 1a */
  2058. X    sprintf(buf128,"%s~%s~%s~",    /* build record */
  2059. X        h_next_msg,
  2060. X        h_act_msg,
  2061. X        h_date) ;
  2062. X    write(fd,buf128,MSGSECT) ;    /* write it */
  2063. X    lseek(fd, 0L, 0);
  2064. X    locking(fd, LK_UNLCK, 0L);
  2065. X    close(fd) ;            /* no need to leave it open */
  2066. X    write(fd1,xtable,4000);
  2067. X    lseek(fd1, 0L, 0);
  2068. X    locking(fd1, LK_UNLCK, 0L);
  2069. X    close(fd1) ;
  2070. X    return(OK) ;
  2071. X    }
  2072. X
  2073. Xhdrread()        /* read the header file into memory */
  2074. X    {
  2075. X    int    fd,
  2076. X        i,
  2077. X        cnt1,
  2078. X        cnt;
  2079. X
  2080. X    strcpy(who_am_i, m_pathname);
  2081. X    strcat(who_am_i, HEADER);
  2082. X    if ((fd = open(who_am_i,READ,0666)) < 0)    /* open input */
  2083. X        {
  2084. X        portsout("Can't open header-file, using inital values!") ;
  2085. X        portsout(CRLF) ;
  2086. X        h_next = 1 ;
  2087. X        h_next_msg[0] = '1' ; h_next_msg[1] = 0 ;
  2088. X        h_act = 1 ;
  2089. X        h_act_msg[0] = '1' ; h_act_msg[1] = 0 ;
  2090. X        h_date[0] = '0' ; h_date[1] = 0 ;
  2091. X        hdrwrt() ; goto next;
  2092. X        }
  2093. X    lseek(fd, 0L, 0);
  2094. X    locking(fd, LK_LOCK, 0L);
  2095. X    if((cnt=read(fd,buf128,MSGSECT)) != MSGSECT)
  2096. X        {
  2097. X        portsout(CRLF) ;
  2098. X            portsout("<<< header read error >>>") ;
  2099. X        portsout(CRLF) ;
  2100. X        return(ERROR) ;
  2101. X        }
  2102. X    cnt = sscanf(buf128,"%[^~]~%[^~]~%[^~]~", 
  2103. X            h_next_msg,
  2104. X            h_act_msg,
  2105. X            h_date) ;
  2106. Xnext:
  2107. X    lseek(fd, 0L, 0);
  2108. X    locking(fd, LK_UNLCK, 0L);
  2109. X    close(fd) ;        /* no need to leave it open */
  2110. X    strcpy(who_am_i, m_pathname);
  2111. X    strcat(who_am_i, CROSSREF);
  2112. X    if ((fd = open(who_am_i,READ,0666)) < 0)
  2113. X        {
  2114. X        portsout("Can't open xref file --- setting values!");
  2115. X        portsout(CRLF);
  2116. X        xtable[0] = 1L;
  2117. X        for (i = 1; i <= 999; i++)
  2118. X            xtable[i] = 0L;
  2119. X        return ;
  2120. X        }
  2121. X    lseek(fd, 0L, 0);
  2122. X    locking(fd, LK_LOCK, 0L);
  2123. X    if ((cnt1=read(fd, xtable, 4000)) != 4000)
  2124. X        {
  2125. X        portsout(CRLF) ;
  2126. X        portsout("<<< xref read error >>>");
  2127. X        portsout(CRLF);
  2128. X        return(ERROR);
  2129. X        }
  2130. X    lseek(fd, 0L, 0);
  2131. X    locking(fd, LK_UNLCK, 0L);
  2132. X    close (fd);
  2133. X/*
  2134. X
  2135. X    if (cnt != 2)
  2136. X        {
  2137. X        return(ERROR) ;
  2138. X        }
  2139. X*/
  2140. X    h_next = atoi(h_next_msg) ;
  2141. X    h_act = atoi(h_act_msg) ;
  2142. X    return(OK) ;
  2143. X    }
  2144. X
  2145. Xmsgopen(how)
  2146. Xint    how ;        /* how to open 0=input, 1=output, 2=i/o */
  2147. X    {
  2148. X    int    fd ;
  2149. X
  2150. X    strcpy(who_am_i, m_pathname);
  2151. X    strcat(who_am_i, MESSAGES);
  2152. X    if ((fd = open(who_am_i,how,0666)) < 0)    /* open i/o */
  2153. X        {
  2154. X        portsout("can't open message-file, will create it!") ;
  2155. X        portsout(CRLF) ;
  2156. X        if ((fd = creat(who_am_i,0666)) < 0)
  2157. X            {
  2158. X            portsout("can't create message-file, aborting!") ;
  2159. X            portsout(CRLF) ;
  2160. X            return(ERROR) ;
  2161. X            }
  2162. X        }
  2163. X    lseek(fd, 0L, 0);
  2164. X    locking(fd, LK_RLCK, 0L);
  2165. X    return(fd) ;
  2166. X    }
  2167. X
  2168. Xmsgclose(fd)
  2169. Xint    fd ;
  2170. X    {
  2171. X    lseek(fd, 0L, 0);
  2172. X    locking(fd, LK_UNLCK, 0L);
  2173. X    return(close(fd)) ;
  2174. X    }
  2175. X
  2176. Xmsgwrt(fd)        /* write the message file from memory variables */
  2177. Xint    fd;        /* writes a message starting with the h_next msg # */
  2178. X    {
  2179. X    int    rc,            /* return code */
  2180. X        cnt1,
  2181. X        cnt2,
  2182. X        len;
  2183. X
  2184. X    rc = cnt1 = len = cnt2 = 0 ;
  2185. X    itoa(this1,h_next) ;                /* convert int to char */
  2186. X    xtable[h_act - 1] = h_next;
  2187. X    for( len=h_act; len < 1000; len++)
  2188. X        xtable[len] = 0L;        /* guarantee clean table */
  2189. X    h_act++;
  2190. X    rc = seek(fd,h_next - 1,0) ;        /* seek next available sector */
  2191. X    h_next++ ;
  2192. X    itoa(next1,h_next) ;
  2193. X    strfill(buf128,0,MSGSECT) ;        /* init buf128 to all hex 00 */
  2194. X/*
  2195. X*            build first piece of msg record
  2196. X*/
  2197. X    sprintf(buf128,"%-10s~%-10s~%-2s~%-9s~%-15s~%-21s~%-21s~%-11s~%-21s~",
  2198. X        this1,                    /* this rcd # */
  2199. X        next1,                    /*  points next rcd # */
  2200. X        msg_delete,                /* delete byte */
  2201. X        msg_date,
  2202. X        msg_time,
  2203. X        msg_to,
  2204. X        msg_from,
  2205. X        msg_pass,
  2206. X        msg_subject);
  2207. X    rc = write(fd,buf128,MSGSECT);    /* write the first 128 byte record */
  2208. X                    /*  for a message record */
  2209. X/*
  2210. X*            build the n+1 piece of msg record
  2211. X*/
  2212. X
  2213. X    len = (strlen(msg_text) / MSG1MAX) + 1; /* calc how many more 128 */
  2214. X                        /*  byte records to write */
  2215. X    cnt2 = 1 ;                /* init for substr */
  2216. X    while (len--)
  2217. X        {
  2218. X        itoa(this1,h_next);        /* calc/convert record #'s */
  2219. X        h_next++;                      
  2220. X        if (len == 0)
  2221. X            {
  2222. X            strcpy(next1,"0");    /* marks last 128 byte piece */
  2223. X            }            /*  of a msg */
  2224. X        else
  2225. X            {
  2226. X            itoa(next1,h_next);
  2227. X            }
  2228. X        strfill(bufmsg0,0,MSG1MAX);
  2229. X        substr(msg_text,bufmsg0,cnt2,MSG1MAX); /* mv MSG1MAX to buff */
  2230. X        cnt2 += MSG1MAX;        /* up cnt2 by MSG1MAX */
  2231. X        strfill(buf128,0,MSGSECT);    /* init buf128 to all hex 00 */
  2232. X        sprintf(buf128,"%-10s~%-10s~%-2s~%-102s~",
  2233. X            this1,            /* this rcd # */
  2234. X            next1,            /* point to next rcd # */
  2235. X            msg_delete,        /* delete byte */
  2236. X            bufmsg0);        /* piece of msg */
  2237. X        rc = write(fd,buf128,MSGSECT);    /* write n+1 128 byte record */
  2238. X        }
  2239. X
  2240. X    strfill(buf128,26,MSGSECT);        /* fill with all hex 1a */
  2241. X    rc = write(fd,buf128,MSGSECT);    /* write all hex 1a 128 byte record */
  2242. X    return(OK);
  2243. X    }
  2244. X
  2245. Xmsgrewrt(fd,r_msg)    /* re-write the message file from memory variables */
  2246. Xint    fd,        /* re-writes only the 1st part of a message */
  2247. X    r_msg;        /* used to update the delete byte */
  2248. X    {
  2249. X    int    rc,            /* return code */
  2250. X        cnt1,
  2251. X        file_size;
  2252. X
  2253. X    rc = cnt1 = 0;
  2254. X    if (r_msg > h_next)    /* don't try to seek past end of file */
  2255. X        {
  2256. X        return(ERROR);
  2257. X        }
  2258. X    if ((rc = seek(fd,r_msg-1,0)) == ERROR)    /* seek to requested sector */
  2259. X        {
  2260. X        return(ERROR);
  2261. X        }
  2262. X    itoa(this1,r_msg);        /* convert int to char */
  2263. X    r_msg++;
  2264. X    itoa(next1,r_msg);
  2265. X    strfill(buf128,0,MSGSECT);        /* init buf128 to all hex 00 */
  2266. X/*
  2267. X*            build first piece of msg record
  2268. X*/
  2269. X    sprintf(buf128,"%-10s~%-10s~%-2s~%-9s~%-15s~%-21s~%-21s~%-11s~%-21s~",
  2270. X        this1,                    /* this rcd # */
  2271. X        next1,                    /* points next rcd # */
  2272. X        msg_delete,                /* delete byte */
  2273. X        msg_date,
  2274. X        msg_time,
  2275. X        msg_to,
  2276. X        msg_from,
  2277. X        msg_pass,
  2278. X        msg_subject);
  2279. X    rc = write(fd,buf128,MSGSECT);    /* write the first 128 byte record */
  2280. X                    /*  for a message record */
  2281. X    return(OK);
  2282. X    }
  2283. X
  2284. X
  2285. Xmsgread(fd,msgno)        /* read message number requested */
  2286. Xint    fd,            /* returns ERROR if msg past eof */
  2287. X    msgno;            /* returns 0 if msg is not 1st piece */
  2288. X                /*   of a message */
  2289. X                /* returns 0 if msg is deleted */
  2290. X                /* returns msg # if successful */
  2291. X    {
  2292. X    int    rc,            /* return code */
  2293. X        msgac,
  2294. X        cnt1,
  2295. X        cnt2,
  2296. X        len,
  2297. X        next,
  2298. X        ret_this,
  2299. X        file_size;
  2300. X    char     act[11];
  2301. X
  2302. X    msgac = xtable[msgno - 1];
  2303. X    if (msgac > h_next)        /* don't try to seek past end of file */
  2304. X        {
  2305. X        return(ERROR);
  2306. X        }
  2307. X    if (msgac == 0)
  2308. X        {
  2309. X        return(ERROR);
  2310. X        }
  2311. X    if ((rc = seek(fd,msgac-1,0)) == ERROR)
  2312. X        {
  2313. X        portsout(CRLF) ;
  2314. X        portsout("Can't seek on message-file!") ;
  2315. X        portsout(CRLF) ;
  2316. X        return(ERROR);        /* when cant find it */
  2317. X        }
  2318. X    if (read(fd,buf128,MSGSECT) != MSGSECT) /* read 128 byte sector */
  2319. X        {
  2320. X        portsout(CRLF) ;
  2321. X        portsout("Can't read in message-file!") ;
  2322. X        portsout(CRLF) ;
  2323. X        return(ERROR);
  2324. X        }
  2325. X/*
  2326. X*            get first piece of msg record
  2327. X*/
  2328. X/* do trial read, since if not first record, fields might overflow */
  2329. Xrc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~",
  2330. X    buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp) ;
  2331. X    if (rc != 9)        /* makes sure we read the 1st piece */
  2332. X        {        /*  of a message and not in the middle */
  2333. X        return(0);    /* 0 when is not the msg header */
  2334. X        }
  2335. X/* now do the real read since looks like is a good record */
  2336. Xrc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~",
  2337. X        this1,                /* this rcd # */
  2338. X        next1,                /*  points to next rcd # */
  2339. X        msg_delete,            /* delete byte */
  2340. X        msg_date,
  2341. X        msg_time,
  2342. X        msg_to,
  2343. X        msg_from,
  2344. X        msg_pass,
  2345. X        msg_subject);
  2346. X    if (rc != 9)        /* makes sure we read the 1st piece */
  2347. X        {        /*  of a message and not in the middle */
  2348. X        return(0);    /* 0 when is not the msg header */
  2349. X        }
  2350. X
  2351. X    if (msg_delete[0] == '9')    /* check for deleted messages */
  2352. X        {            /*  if so, return as if not found */
  2353. X        return(0);
  2354. X        }
  2355. X
  2356. X    ret_this = atoi(this1);    /* return this msg no. */
  2357. X    next = atoi(next1);
  2358. X    itoa(act,msgno);
  2359. X    strcpy(msg_no,act);
  2360. X    if(msg_delete[0] == '5')
  2361. X        {
  2362. X        strcat(msg_no,"*");
  2363. X        strcpy(msg_subject,"< Private Msg >");
  2364. X        }
  2365. X    msg_text[0] = '\0';
  2366. X    while (next)            /* read until no more pieces for */
  2367. X        {            /*  this message */
  2368. X        if (read(fd,buf128,MSGSECT) != MSGSECT) /* read next sector */
  2369. X            {
  2370. X            portsout(CRLF) ;
  2371. X            portsout("Can't read in message-file(2)!") ;
  2372. X            portsout(CRLF) ;
  2373. X            return(ERROR);
  2374. X            }
  2375. X        strfill(bufmsg0,0,MSG1MAX);    /* init bufmsg0 to all hex 00 */
  2376. X        rc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~",
  2377. X            this1,            /* this rcd # */
  2378. X            next1,            /* point to next rcd # */
  2379. X            msg_delete,        /* delete byte */
  2380. X            bufmsg0);        /* piece of msg */
  2381. X        next = atoi(next1);
  2382. X        strcat(msg_text,bufmsg0);    /* tag piece of msg to */
  2383. X                        /*  whole msg array */
  2384. X        }
  2385. X    return(ret_this);    /* if all ok, return the msg no. found */
  2386. X    }
  2387. X
  2388. Xmsgreadx(fd,msgno)        /* read message number requested */
  2389. Xint    fd,            /* returns ERROR if msg past eof */
  2390. X    msgno;            /* returns 0 if msg is not 1st piece */
  2391. X                /*   of a message */
  2392. X                /* returns 0 if msg is deleted */
  2393. X                /* returns msg # if successful */
  2394. X    {
  2395. X    int    rc,            /* return code */
  2396. X        msgac,
  2397. X        cnt1,
  2398. X        cnt2,
  2399. X        len,
  2400. X        next,
  2401. X        ret_this,
  2402. X        t1,
  2403. X        t2,
  2404. X        t3,
  2405. X        file_size;
  2406. X    char    who_am_i[99],
  2407. X        who_am_I[99],
  2408. X        sysop[99],
  2409. X        Sysop[99],
  2410. X        act[11];
  2411. X
  2412. X    msgac = xtable[msgno - 1];
  2413. X    if (msgac > h_next)        /* don't try to seek past end of file */
  2414. X        {
  2415. X        return(ERROR);
  2416. X        }
  2417. X    if (msgac == 0)
  2418. X        {
  2419. X        return(ERROR);
  2420. X        }
  2421. X    if ((rc = seek(fd,msgac-1,0)) == ERROR)
  2422. X        {
  2423. X        portsout(CRLF) ;
  2424. X        portsout("Can't seek on message-file!") ;
  2425. X        portsout(CRLF) ;
  2426. X        return(ERROR);        /* when cant find it */
  2427. X        }
  2428. X    if (read(fd,buf128,MSGSECT) != MSGSECT) /* read 128 byte sector */
  2429. X        {
  2430. X        portsout(CRLF) ;
  2431. X        portsout("Can't read in message-file!") ;
  2432. X        portsout(CRLF) ;
  2433. X        return(ERROR);
  2434. X        }
  2435. X/*
  2436. X*            get first piece of msg record
  2437. X*/
  2438. X/* do trial read, since if not first record, fields might overflow */
  2439. Xrc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~",
  2440. X    buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp) ;
  2441. X    if (rc != 9)        /* makes sure we read the 1st piece */
  2442. X        {        /*  of a message and not in the middle */
  2443. X        return(0);    /* 0 when is not the msg header */
  2444. X        }
  2445. X/* now do the real read since looks like is a good record */
  2446. Xrc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~",
  2447. X        this1,
  2448. X        next1,                /*  points to next rcd # */
  2449. X        msg_delete,            /* delete byte */
  2450. X        msg_date,
  2451. X        msg_time,
  2452. X        msg_to,
  2453. X        msg_from,
  2454. X        msg_pass,
  2455. X        msg_subject);
  2456. X    if (rc != 9)        /* makes sure we read the 1st piece */
  2457. X        {        /*  of a message and not in the middle */
  2458. X        return(0);    /* 0 when is not the msg header */
  2459. X        }
  2460. X
  2461. X    if (msg_delete[0] == '9')    /* check for deleted messages */
  2462. X        {            /*  if so, return as if not found */
  2463. X        return(0);
  2464. X        }
  2465. X    if (msg_delete[0] == '5')    /* protected msg */
  2466. X        {
  2467. X        strcpy(who_am_i,w_fname);
  2468. X        strcat(who_am_i," ");
  2469. X        strcat(who_am_i,w_lname);
  2470. X        strcpy(Sysop,SYSOP);
  2471. X        sprintf(sysop,"%-21s",Sysop);
  2472. X        sprintf(who_am_I,"%-21s",who_am_i);
  2473. X        t1=strcmp(who_am_I,sysop);
  2474. X        t2=strcmp(who_am_I,msg_to);
  2475. X        t3=strcmp(who_am_I,msg_from);
  2476. X        if (t1 == 0 || t2 == 0 || t3 == 0 || user_priv == 32767)
  2477. X            {
  2478. X            goto zzzz;
  2479. X            }
  2480. X        return(-10);
  2481. X        }
  2482. Xzzzz:
  2483. X
  2484. X    ret_this = atoi(this1);    /* return this msg no. */
  2485. X    next = atoi(next1);
  2486. X    itoa(act,msgno);
  2487. X    strcpy(msg_no,act);
  2488. X    msg_text[0] = '\0';
  2489. X    while (next)            /* read until no more pieces for */
  2490. X        {            /*  this message */
  2491. X        if (read(fd,buf128,MSGSECT) != MSGSECT) /* read next sector */
  2492. X            {
  2493. X            portsout(CRLF) ;
  2494. X            portsout("Can't read in message-file(2)!") ;
  2495. X            portsout(CRLF) ;
  2496. X            return(ERROR);
  2497. X            }
  2498. X        strfill(bufmsg0,0,MSG1MAX);    /* init bufmsg0 to all hex 00 */
  2499. X        rc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~",
  2500. X            this1,            /* this rcd # */
  2501. X            next1,            /* point to next rcd # */
  2502. X            msg_delete,        /* delete byte */
  2503. X            bufmsg0);        /* piece of msg */
  2504. X        next = atoi(next1);
  2505. X        strcat(msg_text,bufmsg0);    /* tag piece of msg to */
  2506. X                        /*  whole msg array */
  2507. X        }
  2508. X    return(ret_this);    /* if all ok, return the msg no. found */
  2509. X    }
  2510. Xmsgreadk(fd,msgno)        /* read message number requested */
  2511. Xint    fd,            /* returns ERROR if msg past eof */
  2512. X    msgno;            /* returns 0 if msg is not 1st piece */
  2513. X                /*   of a message */
  2514. X                /* returns 0 if msg is deleted */
  2515. X                /* returns msg # if successful */
  2516. X    {
  2517. X    int    rc,            /* return code */
  2518. X        msgac,
  2519. X        cnt1,
  2520. X        cnt2,
  2521. X        len,
  2522. X        next,
  2523. X        ret_this,
  2524. X        t1,
  2525. X        t2,
  2526. X        t3,
  2527. X        file_size;
  2528. X    char    who_am_i[99],
  2529. X        who_am_I[99],
  2530. X        sysop[99],
  2531. X        Sysop[99],
  2532. X        act[11];
  2533. X
  2534. X    msgac = xtable[msgno - 1];
  2535. X    if (msgac > h_next)        /* don't try to seek past end of file */
  2536. X        {
  2537. X        return(ERROR);
  2538. X        }
  2539. X    if (msgac == 0)
  2540. X        {
  2541. X        return(ERROR);
  2542. X        }
  2543. X    if ((rc = seek(fd,msgac-1,0)) == ERROR)
  2544. X        {
  2545. X        portsout(CRLF) ;
  2546. X        portsout("Can't seek on message-file!") ;
  2547. X        portsout(CRLF) ;
  2548. X        return(ERROR);        /* when cant find it */
  2549. X        }
  2550. X    if (read(fd,buf128,MSGSECT) != MSGSECT) /* read 128 byte sector */
  2551. X        {
  2552. X        portsout(CRLF) ;
  2553. X        portsout("Can't read in message-file!") ;
  2554. X        portsout(CRLF) ;
  2555. X        return(ERROR);
  2556. X        }
  2557. X/*
  2558. X*            get first piece of msg record
  2559. X*/
  2560. X/* do trial read, since if not first record, fields might overflow */
  2561. Xrc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~",
  2562. X    buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp) ;
  2563. X    if (rc != 9)        /* makes sure we read the 1st piece */
  2564. X        {        /*  of a message and not in the middle */
  2565. X        return(0);    /* 0 when is not the msg header */
  2566. X        }
  2567. X/* now do the real read since looks like is a good record */
  2568. Xrc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~",
  2569. X        this1,
  2570. X        next1,                /*  points to next rcd # */
  2571. X        msg_delete,            /* delete byte */
  2572. X        msg_date,
  2573. X        msg_time,
  2574. X        msg_to,
  2575. X        msg_from,
  2576. X        msg_pass,
  2577. X        msg_subject);
  2578. X    if (rc != 9)        /* makes sure we read the 1st piece */
  2579. X        {        /*  of a message and not in the middle */
  2580. X        return(0);    /* 0 when is not the msg header */
  2581. X        }
  2582. X
  2583. X    if (msg_delete[0] == '9')    /* check for deleted messages */
  2584. X        {            /*  if so, return as if not found */
  2585. X        return(0);
  2586. X        }
  2587. X    strcpy(who_am_i,w_fname);
  2588. X    strcat(who_am_i," ");
  2589. X    strcat(who_am_i,w_lname);
  2590. X    strcpy(Sysop,SYSOP);
  2591. X    sprintf(sysop,"%-21s",Sysop);
  2592. X    sprintf(who_am_I,"%-21s",who_am_i);
  2593. X    t1=strcmp(who_am_I,sysop);
  2594. X    t2=strcmp(who_am_I,msg_to);
  2595. X    t3=strcmp(who_am_I,msg_from);
  2596. X    if (t1 == 0 || t2 == 0 || t3 == 0 || user_priv == 32767)
  2597. X        {
  2598. X        goto yyyy;
  2599. X        }
  2600. X    return(-10);
  2601. Xyyyy:
  2602. X
  2603. X    ret_this = atoi(this1);    /* return this msg no. */
  2604. X    next = atoi(next1);
  2605. X    itoa(act,msgno);
  2606. X    strcpy(msg_no,act);
  2607. X    msg_text[0] = '\0';
  2608. X    while (next)            /* read until no more pieces for */
  2609. X        {            /*  this message */
  2610. X        if (read(fd,buf128,MSGSECT) != MSGSECT) /* read next sector */
  2611. X            {
  2612. X            portsout(CRLF) ;
  2613. X            portsout("Can't read in message-file(2)!") ;
  2614. X            portsout(CRLF) ;
  2615. X            return(ERROR);
  2616. X            }
  2617. X        strfill(bufmsg0,0,MSG1MAX);    /* init bufmsg0 to all hex 00 */
  2618. X        rc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~",
  2619. X            this1,            /* this rcd # */
  2620. X            next1,            /* point to next rcd # */
  2621. X            msg_delete,        /* delete byte */
  2622. X            bufmsg0);        /* piece of msg */
  2623. X        next = atoi(next1);
  2624. X        strcat(msg_text,bufmsg0);    /* tag piece of msg to */
  2625. X                        /*  whole msg array */
  2626. X        }
  2627. X    return(ret_this);    /* if all ok, return the msg no. found */
  2628. X    }
  2629. X/*    end of program      */
  2630. END_OF_FILE
  2631.   if test 15763 -ne `wc -c <'bbscfile.c'`; then
  2632.     echo shar: \"'bbscfile.c'\" unpacked with wrong size!
  2633.   fi
  2634.   # end of 'bbscfile.c'
  2635. fi
  2636. if test -f 'bbscmisc.c' -a "${1}" != "-c" ; then 
  2637.   echo shar: Will not clobber existing file \"'bbscmisc.c'\"
  2638. else
  2639.   echo shar: Extracting \"'bbscmisc.c'\" \(2034 characters\)
  2640.   sed "s/^X//" >'bbscmisc.c' <<'END_OF_FILE'
  2641. X
  2642. X#include "bbscdef.h"
  2643. X#include <string.h>
  2644. X#include <ctype.h>
  2645. X#include <sys/types.h>
  2646. X#include <sys/stat.h>
  2647. X
  2648. Xstrfill(buf,fillchar,length)    /* fill a string with fillchar */
  2649. Xchar    *buf;            /*  for length -1 */
  2650. Xint    fillchar,
  2651. X    length;
  2652. X    {
  2653. X    while(--length)        /* really is length -1 */
  2654. X        {
  2655. X        *buf++ = fillchar;
  2656. X        }
  2657. X    *buf++ = '\0';        /* need room for this */
  2658. X    }
  2659. X#ifndef ATT3B1
  2660. X
  2661. Xsubstr(from,to,start,length)    /* moves chars from "from" to "to" */
  2662. Xchar    *from, *to ;        /*  starting at "start" for */
  2663. X                    /*  "length" number of chars */
  2664. Xint    start, length ;        /* for beginning of string use 1, not 0 */
  2665. X    {
  2666. X    int    cnt;
  2667. X
  2668. X    cnt = 0;
  2669. X
  2670. X    while(--start)        /* adjust sending field pointer */
  2671. X        {
  2672. X        from++;        
  2673. X        }
  2674. X
  2675. X    while((cnt < length) && (*to++ = *from++))    /* do the moving */
  2676. X        {
  2677. X        cnt++;        
  2678. X        }
  2679. X    
  2680. X    *to = '\0';
  2681. X
  2682. X    }
  2683. X#endif
  2684. X
  2685. X#ifdef ATT3B1
  2686. X
  2687. Xsubstr(from,to,start,length)
  2688. Xchar *from,*to;
  2689. Xint start,length;
  2690. X{
  2691. X   int cnt, i;
  2692. X
  2693. X   cnt = 0;
  2694. X   while(--start)
  2695. X       from++;
  2696. X
  2697. X   i=0;
  2698. X   while(cnt < length)
  2699. X      if (from[i] == NULL)
  2700. X         break;
  2701. X      else {
  2702. X         to[i] = from[i];
  2703. X         i++;
  2704. X         cnt++;
  2705. X     }
  2706. X
  2707. X   to[i] = NULL;
  2708. X}
  2709. X
  2710. X#endif
  2711. X
  2712. Xitoa(str,n)        /* taken from float.c */
  2713. Xchar *str;
  2714. X    {
  2715. X    sprintf(str,"%d",n) ;
  2716. X    }
  2717. X/*    end of function        */
  2718. X
  2719. Xseek(fildes,posit,dummy) int fildes,posit,dummy ;
  2720. X    {
  2721. Xlong    pos;
  2722. X    pos = posit * 128L ;
  2723. X/*    return(lseek(fildes,posit << 7,0)) ;    */
  2724. X    return(lseek(fildes,pos,0)) ;
  2725. X    }
  2726. X/*    end of function        */
  2727. X
  2728. Xchar *basename(x)  char *x;
  2729. X{
  2730. X    char *ptr;
  2731. X    ptr = strrchr(x, '/');
  2732. X    if ( ptr == (char *)NULL )
  2733. X        return(x);
  2734. X    else
  2735. X        return(++ptr);
  2736. X}
  2737. X
  2738. Xint legalname( co, strg )
  2739. Xchar *co, *strg;
  2740. X{
  2741. X    char *ptr, *indx;
  2742. X    int i;
  2743. X    ptr = co;
  2744. X    while ( *ptr ) {
  2745. X        i = (int) *ptr++;
  2746. X        indx = strchr(strg, i);
  2747. X        if ( indx != NULL )
  2748. X            return(0);
  2749. X    }
  2750. X    return(1);
  2751. X}
  2752. X
  2753. Xint asciicheck(fne)
  2754. Xchar *fne;
  2755. X{
  2756. X    FILE *tbuf;
  2757. X    int datar;
  2758. X    if((tbuf = fopen(fne, "r")) == NULL )
  2759. X        return(0);
  2760. X    while ((datar = getc(tbuf)) != EOF ) {
  2761. X        if(isprint(datar) == 0 && isspace(datar) == 0) {
  2762. X            fclose(tbuf);
  2763. X            return(0);
  2764. X        }
  2765. X    }
  2766. X    fclose(tbuf);
  2767. X    return(1);
  2768. X}
  2769. X    
  2770. X    
  2771. X/*    end of program      */
  2772. END_OF_FILE
  2773.   if test 2034 -ne `wc -c <'bbscmisc.c'`; then
  2774.     echo shar: \"'bbscmisc.c'\" unpacked with wrong size!
  2775.   fi
  2776.   # end of 'bbscmisc.c'
  2777. fi
  2778. echo shar: End of archive 3 \(of 11\).
  2779. cp /dev/null ark3isdone
  2780. MISSING=""
  2781. for I in 1 2 3 4 5 6 7 8 9 10 11 ; do
  2782.     if test ! -f ark${I}isdone ; then
  2783.     MISSING="${MISSING} ${I}"
  2784.     fi
  2785. done
  2786. if test "${MISSING}" = "" ; then
  2787.     echo You have unpacked all 11 archives.
  2788.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2789. else
  2790.     echo You still must unpack the following archives:
  2791.     echo "        " ${MISSING}
  2792. fi
  2793. exit 0
  2794. exit 0 # Just in case...
  2795.