home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol150 / 211misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1984-04-29  |  9.0 KB  |  308 lines

  1. /************************************************************************/
  2. /*                misc.c                    */
  3. /*                                    */
  4. /*    Random functions...                        */
  5. /************************************************************************/
  6.  
  7. /************************************************************************/
  8. /*                history                 */
  9. /* 83Jul13 BAK  Looking for Rcpm bug                    */
  10. /* 83Jun11 BAK  Correcting userlog error - forces write of data.    */
  11. /* 83Mar12 CrT    from msg.c                        */
  12. /* 83Mar03 CrT & SB   Various bug fixes...                */
  13. /* 83Feb27 CrT    Save private mail for sender as well as recipient.    */
  14. /* 83Feb23    Various.  transmitFile() won't drop first char on WC... */
  15. /* 82Dec06 CrT    2.00 release.                        */
  16. /* 82Nov05 CrT    Stream retrieval.  Handles messages longer than MAXTEXT.*/
  17. /* 82Nov04 CrT    Revised disk format implemented.            */
  18. /* 82Nov03 CrT    Individual history begun.  General cleanup.        */
  19. /************************************************************************/
  20.  
  21. #include "b:210ctdl.h"
  22.  
  23. /************************************************************************/
  24. /*                contents                */
  25. /*                                    */
  26. /*    configure()        sets terminal parameters via dialogue    */
  27. /*    doCR()            newline on modem and console        */
  28. /*    download()        menu-level routine for WC-protocol sends*/
  29. /*    patchDebug()        display/patch byte            */
  30. /*    printDate()        prints out date             */
  31. /*    putFlChar()        readFile() -> disk file interface    */
  32. /*    putWCChar()        filter[]s, readFile() to putMsgChar()    */
  33. /*    transmitFile()        send a host file, no formatting     */
  34. /*    tutorial()        prints a .hlp file            */
  35. /*    upload()        menu-level read-via-WC-protocol fn    */
  36. /*    visible()        convert control chars to letters    */
  37. /************************************************************************/
  38.  
  39. /************************************************************************/
  40. /*    configure() sets up terminal width etc via dialogue        */
  41. /************************************************************************/
  42. configure() {
  43.    termWidth    = getNumber(" Screen width",          10, 255);
  44.    termNulls    = getNumber(" #Nulls",               0, 255);
  45.    termUpper    = getYesNo(" Uppercase only"            ) ?  UCMASK  :  0;
  46.    termLF    = getYesNo(" Linefeeds"             ) ?  LFMASK  :  0;
  47.    termTab    = getYesNo(" Tabs"                ) ?  TABMASK :  0;
  48.    expert    =!getYesNo(" Helpful hints"            ) ?  EXPERT  :  0;
  49.    Storelog();
  50. /* Forces write to eliminate phantom configurations... */  
  51. }
  52.  
  53. /************************************************************************/
  54. /*    doCR() does a newline on modem and console            */
  55. /************************************************************************/
  56. doCR() {
  57.     int i;
  58.  
  59.     crtColumn    = 1;
  60.     if (outFlag) return;    /* output is being s(kip)ped    */
  61.  
  62.     if (whichIO==CONSOLE || echo==BOTH)   putCh(NEWLINE);
  63.     if (haveCarrier) {
  64.     if (!usingWCprotocol) {
  65.         outmod('\r');
  66.         for (i=termNulls;  i;  i--) outmod(0);
  67.         if (termLF) outmod('\n');
  68.     } else {
  69.         sendWCChar('\r');
  70.         if (termLF) sendWCChar('\n');
  71.     }
  72.     }
  73. #ifdef XYZZY
  74. /* test code only */
  75.     else {
  76.     if (usingWCprotocol) {
  77.         sendWCChar('\r');
  78.         if (termLF) sendWCChar('\n');
  79.     }
  80.     }
  81. #endif
  82.     prevChar    = ' ';
  83. }
  84.  
  85. /************************************************************************/
  86. /*    download() is the menu-level send-message-via-WC-protocol fn    */
  87. /************************************************************************/
  88. download(whichMess, revOrder)
  89. char whichMess, revOrder;
  90. {
  91.     outFlag    = OUTOK;
  92.     if (!expert)   tutorial("wcdown.blb");
  93.  
  94.     outFlag    = OUTOK;
  95.     if (!getYesNo("Ready"))  return;
  96.  
  97.     /* here we go: */
  98.     echo        = NEITHER;
  99.     usingWCprotocol    = TRUE     ;    /* all points bulletin        */
  100.  
  101.     SFRunning    = TRUE;         /* init sendWCChar coroutine    */
  102.     showMessages(whichMess, revOrder);
  103.  
  104.     while (sendWCChar(ERROR) == FALSE); /* fill last 128-byte block    */
  105.  
  106.     setUp(FALSE);
  107.     usingWCprotocol    = FALSE  ;
  108. }
  109.  
  110.  
  111. /************************************************************************/
  112. /*    patchDebug()                            */
  113. /************************************************************************/
  114. patchDebug() {
  115.     unsigned  i, j, page;
  116.     char c, finished, *pc;
  117.  
  118.     mPrintf("\bpatch\n ");
  119.     page = getNumber("page", 0, 255);
  120.     finished = FALSE;
  121.     do {
  122.     for (i=16, pc= (page*256);  i;    i--)   {
  123.         mPrintf("%d ", pc);
  124.         for (j=16;    j;  j--)   {
  125.         mPrintf("%c", visible(*pc++));
  126.         }
  127.         mPrintf("\n ");
  128.     }
  129.     switch (toLower(iChar()))   {
  130.     case 'r':
  131.         pc    = getNumber("adr", 0, 65355);
  132.         *pc = getNumber("val", 0, 255);
  133.         break;
  134.     case 'n':    page++;         break;
  135.     case 'p':    page--;         break;
  136.     default:    finished = TRUE;    break;
  137.     }
  138.     } while (!finished);
  139. }
  140.  
  141. /************************************************************************/
  142. /*    printDate() prints out a date packed in two-byte format     */
  143. /************************************************************************/
  144. printDate(year, month, day)
  145. char year, month, day;
  146. {
  147.     mprintf("%d%s%02d ", year, monthTab[month], day);
  148. }
  149.  
  150. /************************************************************************/
  151. /*    putFlChar() is used to upload files                */
  152. /*    returns: ERROR on problems else TRUE                */
  153. /*    Globals: msgBuf.mbtext is used as a buffer, to save space    */
  154. /************************************************************************/
  155. putFlChar(c)
  156. char c;
  157. {
  158.     return  putC(c, msgBuf.mbtext) != ERROR;
  159. }
  160.  
  161. /************************************************************************/
  162. /************************************************************************/
  163. /*    putWCChar() filter[]s from readFile() to putMsgChar()        */
  164. /*    Returns: ERROR if problems, else TRUE                */
  165. /*    Globals: outFlag is set to OUTSKIP when an ascii EOF (^Z) is    */
  166. /*        encountered, and no further text is written to disk.    */
  167. /************************************************************************/
  168. int putWCChar(c)
  169. int c;
  170. {
  171.     if (outFlag)    return TRUE;    /* past ascii EOF.  ignore.    */
  172.  
  173.     if (c == ERROR) {
  174.     /* EOF.  Note for overkill:    */
  175.     outFlag = OUTSKIP;
  176.     return TRUE;
  177.     }
  178.  
  179.     c    &= 0x7F;    /* cut high stuff off    */
  180.  
  181.     if (c == CPMEOF) {
  182.     /* ascii EOF.  Ignore rest of file:    */
  183.     outFlag = OUTSKIP;
  184.     return TRUE;
  185.     }
  186.  
  187.     return  putMsgChar(filter[c]);
  188. }
  189.  
  190. /************************************************************************/
  191. /*    transmitFile() dumps a host file with no formatting        */
  192. /************************************************************************/
  193. transmitFile(filename)
  194. char *filename;
  195. {
  196.     char mAbort();
  197.     int  getc(), sendWCChar();
  198.     char fbuf[BUFSIZ], fname[NAMESIZE];
  199.     int  c;
  200.  
  201.     outFlag    = OUTOK;
  202.  
  203.     unspace(filename, fname);
  204.  
  205.     if(fopen(fname, fbuf) == ERROR) {
  206.     mprintf("\n No %s.\n", fname);
  207.     return(ERROR);
  208.     }
  209.  
  210.     doCR();
  211.     if (usingWCprotocol)   {
  212.     SFRunning   = TRUE;
  213.     sendWCChar('\0');    /* warm up routine    */
  214.     }
  215.  
  216.     while ((c=getc(fbuf)) != ERROR)  {
  217.     putCh(c);
  218.     if (whichIO == MODEM) {
  219.         if (!usingWCprotocol)    outMod(c)    ;
  220.         else            sendWCChar(c);
  221.     }
  222.     if (textDownload  &&  c==CPMEOF)   break;
  223.     if (textDownload  &&  mAbort() )   break;
  224.     }
  225.  
  226.     if (usingWCprotocol)   while (sendWCChar(ERROR) == FALSE);
  227.  
  228.     fClose(fbuf);
  229. }
  230.  
  231. /************************************************************************/
  232. /*    tutorial() prints file <filename> on the modem & console    */
  233. /*    Returns:    TRUE on success else ERROR            */
  234. /************************************************************************/
  235. #define MAXWORD 256
  236. tutorial(filename)
  237. char *filename;
  238. {
  239.     char fbuf[BUFSIZ];
  240.     char line[MAXWORD];
  241.     int  toReturn;
  242.  
  243.     toReturn    = TRUE;
  244.  
  245.     outFlag    = OUTOK;
  246.     if(fopen(filename, fbuf) == ERROR) {
  247.     mPrintf("\n No %s.\n", filename);
  248.     toReturn    = ERROR;
  249.     } else {
  250.     if (!expert)   mPrintf("\n <J>ump <P>ause <S>top\n");
  251.     mPrintf(" \n");
  252.     while (fGetS(line, fbuf))   mPrintf("%s", line);
  253.     fClose(fbuf);
  254.     }
  255.  
  256.     return   toReturn;
  257. }
  258.  
  259. /************************************************************************/
  260. /*    upLoad() enters a file into current directory            */
  261. /************************************************************************/
  262. upLoad() {
  263.     char fileName[NAMESIZE], *s;
  264.     int putFlChar();
  265.  
  266.     getString("filename", fileName, NAMESIZE);
  267.     normalizeString(fileName);
  268.  
  269.     if (fileName[1] != ':')   s = &fileName[0];
  270.     else              s = &fileName[2];
  271.  
  272.  
  273.     setSpace(roomBuf.rbdisk, roomBuf.rbuser);
  274.  
  275.     if(fOpen(s, msgBuf.mbtext) != ERROR) {
  276.     mprintf("\n A %s already exists.\n", s);
  277.     } else {
  278.     if (!expert) {
  279.         setSpace(homeDisk, homeUser);
  280.         tutorial("wcupload.blb");
  281.         setSpace(roomBuf.rbdisk, roomBuf.rbuser);
  282.     }
  283.     if (fCreat(s, msgBuf.mbtext) == ERROR) {
  284.         mprintf("\n Can't create %s!\n", s);
  285.     } else {
  286.  
  287.         readFile(putFlChar);
  288.  
  289.         fFlush(msgBuf.mbtext);
  290.         fClose(msgBuf.mbtext);
  291.     }
  292.     }
  293.     setSpace(homeDisk, homeUser);
  294. }
  295.  
  296. /************************************************************************/
  297. /*    visible() converts given char to printable form if nonprinting    */
  298. /************************************************************************/
  299. char visible(c)
  300. char c;
  301. {
  302.     if (c==0xFF)  c = '$'    ;   /* start-of-message in message.buf    */
  303.     c            = c & 0x7F    ;   /* kill high bit otherwise        */
  304.     if ( c < ' ') c = c + 'A' -1;   /* make all control chars letters    */
  305.     if (c== 0x7F) c = '~'    ;   /* catch DELETE too         */
  306.     return(c);
  307. }
  308.