home *** CD-ROM | disk | FTP | other *** search
/ Amiga Times / AmigaTimes.iso / programme / trionbbs110 / Trion / docs / RIPdoors / adoor.c next >
Encoding:
C/C++ Source or Header  |  1998-10-06  |  21.1 KB  |  932 lines

  1.  
  2.  
  3. /*  Trion BBS 'Additional Clidoor Support' system functions             */
  4. /*                                                                      */
  5. /*  V 1.00   25 - 11 - 1995                                             */
  6. /*  V 1.10    7 -  6 - 1997                                             */
  7. /*                                                                      */
  8. /*  (c) Copyright 1995-98 by Paul Spijkerman                            */
  9.  
  10.  
  11.  
  12. #include  "adoor.h"
  13.  
  14.  
  15. int  SendMessage    (struct ADS_Data *p);
  16. int  SafePutToPort  (struct Message *, STRPTR);
  17.  
  18.  
  19.  
  20.  
  21. /*===( Input / Output code )=================================*/
  22.  
  23.  
  24. void SetOpIO(struct DoorIO *p)
  25. {
  26.    p->ConInput  = Input();
  27.    p->ConOutput = Output();
  28.  
  29.    p->carrier = 1;
  30.  
  31.    SetMode (p->ConInput , 1);     /* RAW: mode */
  32.  
  33.    p->xmax = 80;
  34.    p->ymax = 40;
  35.  
  36.    p->kar  = 0;
  37.  
  38.    norm(p);      /*   mfc, mbc, mhigh  */
  39.    cls (p);      /*   mx,  my          */
  40. }
  41.  
  42.  
  43. void RemoveIO(struct DoorIO *p)
  44. {
  45.    SetMode (p->ConInput , 0);     /* CON: mode */
  46. }
  47.  
  48.  
  49. /* 'Normal' GetCharacter() function */
  50.  
  51. /*
  52. UBYTE GetCharacter(struct DoorIO *p)
  53. {
  54.    UBYTE c = 0, getstring[3];
  55.  
  56.    while (c == 0 && p->carrier){
  57.       if (0 != WaitForChar( p->ConInput ,10000)){
  58.          Read( p->ConInput , getstring, 1);
  59.          c = getstring[0];
  60.          if (c == 3) p->carrier = 0;        /* carrier lost */
  61.       }
  62.    }
  63.    return c;
  64. }
  65. */
  66.  
  67. /* 'Normal' MayGetCharacter() function */
  68.  
  69. /*
  70. UBYTE MayGetCharacter(struct DoorIO *p)
  71. {
  72.    UBYTE  c = 0, getstring[3];
  73.    getstring[0] = '\0';
  74.  
  75.    if (0 != WaitForChar( p->ConInput , 0)){
  76.       Read( p->ConInput , getstring, 1);      /* IPV getstring -> &c */
  77.       c = getstring[0];
  78.       if (c == 3) p->carrier = 0;             /* carrier lost */
  79.    }
  80.    return c;
  81. }
  82. */
  83.  
  84. /*  GetCharacter() function with code for UnGetCharacter() fuction */
  85.  
  86. UBYTE GetCharacter(struct DoorIO *p)
  87. {
  88.    UBYTE c = 0, getstring[3];
  89.  
  90.    if (p->kar > 0){
  91.       c = p->kar;
  92.       p->kar = 0;
  93.    }else{
  94.       while (c == 0 && p->carrier){
  95.          if (0 != WaitForChar( p->ConInput ,10000)){
  96.             Read( p->ConInput , getstring, 1);
  97.             c = getstring[0];
  98.             if (c == 3) p->carrier = 0;        /* carrier lost */
  99.          }
  100.       }
  101.    }
  102.    return c;
  103. }
  104.  
  105.  
  106. /* Stores ONE character that was read to much                      */
  107. /* Usefull in a 'splitchat' door .. when you read a character from */
  108. /* 'The other side' when you are reading a line 'from this side'   */
  109. /* Just unget the character and finish the line ..                 */
  110.  
  111. void UnGetCharacter(struct DoorIO *p, UBYTE kar)
  112. {
  113.    p->kar = kar;
  114. }
  115.  
  116.  
  117. /*  MayGetCharacter() function with code for UnGetCharacter() fuction */
  118.  
  119. UBYTE MayGetCharacter(struct DoorIO *p)
  120. {
  121.    UBYTE  c = 0, getstring[3];
  122.    getstring[0] = '\0';
  123.  
  124.    if (p->kar > 0){
  125.       c = p->kar;
  126.       p->kar = 0;
  127.    }else{
  128.       if (0 != WaitForChar( p->ConInput , 0)){
  129.          Read( p->ConInput , getstring, 1);      /* IPV getstring -> &c */
  130.          c = getstring[0];
  131.          if (c == 3) p->carrier = 0;             /* carrier lost */
  132.       }
  133.    }
  134.    return c;
  135. }
  136.  
  137.  
  138. int  GetString(struct DoorIO *p, char *str, int strsize)
  139. {
  140.    int   len = 0, pos = 0, t, d;
  141.    UBYTE kar;
  142.  
  143.    while (/*len < strsize-1 &&*/ '\r' != (kar = GetCharacter(p)) &&  Carrier(p)){
  144.  
  145.       /* cursor ->    (2+pos, y) */
  146.       /* nprintf(p, "%d;%dH",27,7 + pos); */
  147.  
  148.       switch (kar){
  149.  
  150.          case 8:                              /* case of backspace */
  151.             if (pos > 0){
  152.                nprintf(p, "D");
  153.                for (t = pos - 1; t < len - 1; t++)
  154.                   nprintf(p, "%c", str[t] = str[t+1] );
  155.                nprintf(p, "%c", str[len-1] = ' ' );
  156.                d = len - pos + 1;
  157.                nprintf(p, "%dD", d);
  158.                len--;
  159.                pos--;
  160.             }
  161.          break;
  162.  
  163.          case 0x7f:                           /* case of Delete */
  164.             if (len > 0 && pos < len){
  165.                for (t = pos; t < len - 1; t++)
  166.                   nprintf(p, "%c", str[t] = str[t+1] );
  167.                nprintf(p, "%c", str[len-1] = ' ' );
  168.                d = len - pos;
  169.                nprintf(p, "%dD", d);
  170.                len--;
  171.             }
  172.          break;
  173.  
  174.          case    0:
  175.          case    3:                           /* ignore Ctrl-c   */
  176.          case '\n':                           /* ignore newlines */
  177.          break;
  178.  
  179.          case 0x1b:                           /* escape (sequence) */
  180.             kar = GetCharacter(p);
  181.             if (kar == '['){
  182.                kar = GetCharacter(p);
  183.                if (kar == 'D'){               /* backward */
  184.                   if (pos > 0){
  185.                      pos--;
  186.                      nprintf(p, "D");
  187.                   }
  188.                }
  189.                if (kar == 'C'){               /* forward  */
  190.                   if (pos < len){
  191.                      pos++;
  192.                      nprintf(p, "C");
  193.                   }
  194.                }
  195.             }
  196.          break;
  197.  
  198.          default:
  199.             if (len < strsize-1){
  200. /*
  201.             str[pos++] = kar;
  202.             if (pos > len)  len = pos;
  203.             nprintf(p, "%c", kar);
  204. */
  205.             if (pos == len){
  206.                str[pos++] = kar;
  207.                if (pos > len)  len = pos;
  208.                nprintf(p, "%c", kar);
  209.             }else{
  210.                for (t = len; t >= pos; t--)
  211.                   str[t+1] = str[t];
  212.                str[pos] = kar;
  213.  
  214.                for (t = pos; t <= len; t++)
  215.                   nprintf(p, "%c", str[t]);
  216.  
  217.                d = len - pos;
  218.                nprintf(p, "%dD", d);
  219.                len++;
  220.                pos++;
  221.             }
  222.  
  223.             }
  224.          break;
  225.  
  226.       }
  227.    }
  228.    str[len] = '\0';
  229.    /* nprintf(p, "\r\n"); */
  230.    return len;
  231. }
  232.  
  233.  
  234. int Carrier(struct DoorIO *p)        /* voor de compleet heid :) */
  235. {
  236.    return (p->carrier);
  237. }
  238.  
  239.  
  240. int nprintf(struct DoorIO *p, char *fmt, ...)
  241. {
  242.    int len;
  243.    va_list var_args;
  244.    char str[120];
  245.  
  246.    va_start(var_args, fmt);
  247.    len = (int) vsprintf(str, fmt, var_args);    /* of eigen brouwsel */
  248.    va_end(var_args);
  249.  
  250.    PutStr (str);
  251.    Flush  (p->ConOutput);
  252.    return (len);
  253. }
  254.  
  255.  
  256. int brk(void)
  257. {
  258.    return (0);
  259. }
  260.  
  261.  
  262. /*===( FileMark / Download code )=================================*/
  263.  
  264.  
  265. int  SetopPort(struct ADS_Data *p, int node, int quiet)
  266. {
  267.    int ret = 0;
  268.  
  269.    p->node    = node;
  270.    p->quiet   = quiet;
  271.    p->BBSMsg  = NULL;
  272.    p->BBSreplyport = NULL;
  273.    p->IDMode  = 0;
  274.  
  275.    if (p->node < 0 || p->node > 10){
  276.       if (!p->quiet)   printf("Got an unvalid node number '%d'\n", p->node);
  277.    }else{
  278.  
  279.       if (NULL == (p->BBSreplyport = CreatePort(0,0))){
  280.          if (!p->quiet)    printf("Couldn't create BBSreplyport.\n");
  281.       }else{
  282.  
  283.          if (NULL == (p->BBSMsg = (struct ADoorMessage *) AllocMem(sizeof(struct ADoorMessage), MEMF_PUBLIC | MEMF_CLEAR))){
  284.             if (!p->quiet)    printf("Door couldn't get memory.\n");
  285.          }else{
  286.  
  287.             p->BBSMsg->ADS_Msg.mn_Node.ln_Type = NT_MESSAGE;   /* make up a message, */
  288.             p->BBSMsg->ADS_Msg.mn_Length       = sizeof(struct ADoorMessage);  /* including the replyport.  */
  289.             p->BBSMsg->ADS_Msg.mn_ReplyPort    = p->BBSreplyport;
  290.  
  291.             GetSharedData(p);
  292.  
  293.             ret = 1;    /* succes */
  294.          }
  295.       }
  296.    }
  297.  
  298.    if (ret == 0)  RemovePort(p);
  299.  
  300.    return ret;
  301. }
  302.  
  303.  
  304. int  RemovePort(struct ADS_Data *p)
  305. {
  306.    int ret = 0;
  307.  
  308.    if (p->BBSMsg)        FreeMem    ( p->BBSMsg, sizeof(struct ADoorMessage));
  309.    if (p->BBSreplyport)  DeletePort ( p->BBSreplyport);
  310.  
  311.    return ret;
  312. }
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319. int  DropCarrier(struct ADS_Data *p)
  320. {
  321.    p->BBSMsg->ADS_Command     =   ADSC_DROP_CARRIER;
  322.    return SendMessage( p );
  323. }
  324.  
  325.  
  326. int  PrintToLog(struct ADS_Data *p, char *string)
  327. {
  328.    p->BBSMsg->ADS_Command     =   ADSC_STRING_TO_LOG;
  329.    strcpy (p->BBSMsg->ADS_String , string);
  330.    return SendMessage( p );
  331. }
  332.  
  333.  
  334. /* an extension (.TXT .ANSI .RIP etc.) is not needed */
  335.  
  336. int  TypeFile(struct ADS_Data *p, char *string)
  337. {
  338.    p->BBSMsg->ADS_Command     =   ADSC_TYPE_FILE;
  339.    strcpy (p->BBSMsg->ADS_String , string);
  340.    return SendMessage( p );
  341. }
  342.  
  343. int  GetTimeOnline(struct ADS_Data *p)
  344. {
  345.    int res = -1;
  346.  
  347.    p->BBSMsg->ADS_Command     =   ADSC_GET_TIME_ONLINE;
  348.    res = SendMessage( p );
  349.  
  350.    if (res >= 0){
  351.       return p->BBSMsg->ADS_Data_word;
  352.    }else{
  353.       return -1;
  354.    }
  355. }
  356.  
  357. int  IncreaseTimeOnline(struct ADS_Data *p, int time)
  358. {
  359.    p->BBSMsg->ADS_Command     =   ADSC_CHANGE_TIME_ONLINE;
  360.    p->BBSMsg->ADS_SubCommand  =   1;    /* Increase */
  361.    p->BBSMsg->ADS_Data_word   =   time;
  362.    return SendMessage( p );
  363. }
  364.  
  365. int  DecreaseTimeOnline(struct ADS_Data *p, int time)
  366. {
  367.    p->BBSMsg->ADS_Command     =   ADSC_CHANGE_TIME_ONLINE;
  368.    p->BBSMsg->ADS_SubCommand  =   0;    /* Decrease */
  369.    p->BBSMsg->ADS_Data_word   =   time;
  370.    return SendMessage( p );
  371. }
  372.  
  373.  
  374.  
  375.  
  376.  
  377. int  Download(struct ADS_Data *p)
  378. {
  379.    p->BBSMsg->ADS_Command     =   ADSC_DOWNLOAD_DOS_FILES;
  380.    return SendMessage( p );
  381. }
  382.  
  383.  
  384. int  MarkFile(struct ADS_Data *p, char *str)   /* 79 letters max */
  385. {
  386.    p->BBSMsg->ADS_Command     =   ADSC_MARK_DOS_FILE;
  387.    strcpy (p->BBSMsg->ADS_String , str);
  388.    return SendMessage( p );
  389. }
  390.  
  391.  
  392. int  UnmarkAllFiles(struct ADS_Data *p)
  393. {
  394.    p->BBSMsg->ADS_Command     =   ADSC_UNMARK_ALL_DOSFILES;
  395.    return SendMessage( p );
  396. }
  397.  
  398.  
  399. /* receive a file including path */
  400.  
  401. /* res == 0  ..  No file                    */
  402. /* res == 1  ..  Error (partially received  */
  403. /* res == 2  ..  File received !            */
  404.  
  405.  
  406. int  Upload(struct ADS_Data *p, char *str)   /* 79 letters max */
  407. {
  408.    int res;
  409.  
  410.    p->BBSMsg->ADS_Command     =   ADSC_UPLOAD;
  411.    res = SendMessage( p );
  412.  
  413.    strcpy (str, p->BBSMsg->ADS_String);
  414.    return res;
  415. }
  416.  
  417.  
  418.  
  419.  
  420. int  PageSysop(struct ADS_Data *p)
  421. {
  422.    p->BBSMsg->ADS_Command     =   ADSC_PAGE_SYSOP;
  423.    return SendMessage( p );
  424. }
  425.  
  426.  
  427.  
  428. /* If you want to play a sample multiple times , increase SubCommand */
  429.  
  430.  
  431. int  PlaySample(struct ADS_Data *p, char *sample)
  432. {
  433.    UBYTE  *path;
  434.  
  435.    p->BBSMsg->ADS_Command     =   ADSC_PLAY_SAMPLE;
  436.    p->BBSMsg->ADS_SubCommand  =   1;
  437.  
  438.    /* Simple way to get a path to a sample (provided for example)     */
  439.    /* sprintf (p->BBSMsg->ADS_String,  "trion:samples/%s", sample);   */
  440.  
  441.    /* Get pointer to Samples directory (see TrionRM.cfg)  */
  442.    path = p->SharedData->Paths.Samples;
  443.  
  444.    /* Make a path .. but use the TrionRM.cfg value for path */
  445.    /* sprintf (p->BBSMsg->ADS_String,  "%s%s", path, sample); */
  446.  
  447.    /* Same as above but uses less memory (if you don't use sprintf() */
  448.    /* in your sources) */
  449.    strcpy( p->BBSMsg->ADS_String , path   );
  450.    strcat( p->BBSMsg->ADS_String , sample );
  451.  
  452.    return SendMessage( p );
  453. }
  454.  
  455.  
  456. int  PlaySampleNum  (struct ADS_Data *p, char *sample, int num)
  457. {
  458.    UBYTE  *path;
  459.  
  460.    p->BBSMsg->ADS_Command     =   ADSC_PLAY_SAMPLE;
  461.    p->BBSMsg->ADS_SubCommand  =   num;
  462.  
  463.    /* Simple way to get a path to sample (provided for example)     */
  464.    /* sprintf (p->BBSMsg->ADS_String,  "trion:samples/%s", sample); */
  465.  
  466.    /* Get pointer to Samples directory (see TrionRM.cfg)  */
  467.    path = p->SharedData->Paths.Samples;
  468.  
  469.    /* Make a path .. but use the TrionRM.cfg value for path */
  470.    /* sprintf (p->BBSMsg->ADS_String,  "%s%s", path, sample); */
  471.  
  472.    /* Same as above but uses less memory (if you don't use sprintf() */
  473.    /* in your sources */
  474.    strcpy( p->BBSMsg->ADS_String , path   );
  475.    strcat( p->BBSMsg->ADS_String , sample );
  476.  
  477.    return SendMessage( p );
  478. }
  479.  
  480.  
  481. int   CheckSysopAvailable(struct ADS_Data *p)
  482. {
  483.    int res = -1;
  484.  
  485.    p->BBSMsg->ADS_Command     =   ADSC_CHECK_SYSOP_AVAILABLE;
  486.    res = SendMessage( p );
  487.  
  488.    if (res >= 0){
  489.       return (p->BBSMsg->ADS_Data_word);
  490.    }else{
  491.       return -1;
  492.    }
  493. }
  494.  
  495.  
  496. /* mode == 0   ->   Normal mode   8 bit ASCII  */
  497. /* mode == 1   ->   Chat mode     7 bit ASCII , MSB is the source of character */
  498.  
  499. int  SplitChatMode(struct ADS_Data *p, int mode)
  500. {
  501.    p->IDMode                  =   mode & 1;
  502.    p->BBSMsg->ADS_Command     =   ADSC_SPLIT_CHAT_MODE;
  503.    p->BBSMsg->ADS_SubCommand  =   mode & 1;
  504.    return SendMessage( p );
  505. }
  506.  
  507.  
  508.  
  509. int  GetUserStringField(struct ADS_Data *p, int field, char *string)
  510. {
  511.    int res = -1;
  512.  
  513.    if (field >= 64 && field <= 127){
  514.       p->BBSMsg->ADS_Command     =   ADSC_GET_USER_DATA;
  515.       p->BBSMsg->ADS_SubCommand  =   field;
  516.       res =  SendMessage( p );
  517.  
  518.       if (res >= 0){
  519.          strcpy(string, p->BBSMsg->ADS_String);
  520.       }
  521.    }
  522.    return res;
  523. }
  524.  
  525. int  GetUserNumericalField(struct ADS_Data *p, int field, ULONG *var)
  526. {
  527.    int res = -1;
  528.  
  529.    if (field > 128){
  530.       p->BBSMsg->ADS_Command     =   ADSC_GET_USER_DATA;
  531.       p->BBSMsg->ADS_SubCommand  =   field;
  532.       res =  SendMessage( p );
  533.  
  534.       if (res >= 0){
  535.          *var = p->BBSMsg->ADS_Data_long;
  536.       }
  537.    }
  538.    return res;
  539. }
  540.  
  541. int  ChangeUserStringField(struct ADS_Data *p, int field, char *string)
  542. {
  543.    int res = -1;
  544.  
  545.    if (field >= 64 && field <= 127){
  546.       p->BBSMsg->ADS_Command     =   ADSC_CHANGE_USER_DATA;
  547.       p->BBSMsg->ADS_SubCommand  =   field;
  548.       strcpy(p->BBSMsg->ADS_String, string);
  549.       res =  SendMessage( p );
  550.    }
  551.    return res;
  552. }
  553.  
  554.  
  555. int  GetBaudRate(struct ADS_Data *p, UWORD *local, ULONG *baudrate)
  556. {
  557.    int res = 0;
  558.  
  559.    p->BBSMsg->ADS_Command     =   ADSC_GET_SYSTEM_DATA;
  560.    p->BBSMsg->ADS_SubCommand  =   1;
  561.    res =  SendMessage( p );
  562.  
  563.    *local    = p->BBSMsg->ADS_Data_word;
  564.    *baudrate = p->BBSMsg->ADS_Data_long;
  565.  
  566.    return res;
  567. }
  568.  
  569.  
  570. int  GetSharedData(struct ADS_Data *p)
  571. {
  572.    int res = 0;
  573.  
  574.    p->BBSMsg->ADS_Command     =   ADSC_GET_SYSTEM_DATA;
  575.    p->BBSMsg->ADS_SubCommand  =   2;
  576.    res =  SendMessage( p );
  577.  
  578.    p->SharedData  = p->BBSMsg->ADS_P;
  579.  
  580.    return res;
  581. }
  582.  
  583.  
  584.  
  585.  
  586.  
  587. int  ChangeUserNumericalField(struct ADS_Data *p, int field, ULONG var)
  588. {
  589.    int res = -1;
  590.  
  591.    if (field > 128){
  592.       p->BBSMsg->ADS_Command     =   ADSC_CHANGE_USER_DATA;
  593.       p->BBSMsg->ADS_SubCommand  =   field;
  594.       p->BBSMsg->ADS_Data_long   =   var;
  595.       res =  SendMessage( p );
  596.  
  597.    }
  598.    return res;
  599. }
  600.  
  601.  
  602. int  FlushBuffer(struct ADS_Data *p)
  603. {
  604.    p->BBSMsg->ADS_Command     =   ADSC_FLUSH_BUFFER;
  605.    return SendMessage( p );
  606. }
  607.  
  608.  
  609. int  PushIntoBuffer(struct ADS_Data *p, char *str, int source)   /* 79 letters max */
  610. {
  611.    p->BBSMsg->ADS_Command     =   ADSC_PUSHINTOBUFFER;
  612.    p->BBSMsg->ADS_SubCommand  =   source;
  613.    strcpy (p->BBSMsg->ADS_String , str);
  614.    return SendMessage( p );
  615. }
  616.  
  617.  
  618.  
  619. int  SendMessage(struct ADS_Data *p)  /* int node, struct ADoorMessage *Msg */
  620. {
  621.    struct ADoorMessage  *reply;
  622.    int    result = 0;
  623.    char   portname[20];
  624.  
  625.    sprintf(portname , "tronadoor%d", p->node);
  626.  
  627.    if (SafePutToPort((struct Message *) p->BBSMsg,  portname )){
  628.       WaitPort(p->BBSreplyport);
  629.       if (reply = (struct ADoorMessage *) GetMsg(p->BBSreplyport)){
  630.          result = p->BBSMsg->ADS_Result;
  631.       }else{
  632.          /* print("Error.\n"); */
  633.          result = -3;
  634.       }
  635.    }else{
  636.       if (!p->quiet) printf("Can't find BBS node %d.\n", p->node);
  637.       result = -2;
  638.    }
  639.  
  640.    return result;
  641. }
  642.  
  643.  
  644.  
  645. int  SafePutToPort(struct Message *message, STRPTR portname)
  646. {
  647.    struct MsgPort *port;
  648.  
  649.    Forbid();
  650.    port = FindPort (portname);
  651.    if (port) PutMsg(port, message);
  652.    Permit();
  653.    return(port ? TRUE : FALSE);    /* FALSE if the port was not found */
  654. }
  655.  
  656.  
  657.  
  658.  
  659.  
  660. /*===(  ANSI code  )=================================*/
  661.  
  662.  
  663. #define  apri2buf  printf          /* Buffer code removed    */
  664.                                    /* color buffer inplace   */
  665.                                    /* cursor buffer removed  */
  666.  
  667.  
  668. void cursxy(struct DoorIO *p, int x,int y)
  669. {
  670.    if (y == 1 && x == 1){
  671.       printf("\x1b[H"); 
  672.    }else{
  673.       printf("\x1b[%d;%dH", p->my = y, p->mx = x); 
  674.    }
  675. }
  676.  
  677.  
  678.  
  679. /*
  680. void cursxy(struct DoorIO *p, int x,int y)
  681. {
  682.    if (y == 1 && x == 1){
  683.       apri2buf("\x1b[H"); 
  684.       my = y; mx = x;
  685.    }else{
  686.       if (y != my || x != mx){
  687.          if (y == my){
  688.             if (x > mx)
  689.                forward(x - mx,0);
  690.             else
  691.                backward(mx - x);
  692.          }else{
  693.             if (x == mx){
  694.                if (y > my)
  695.                   down(y - my);
  696.                else
  697.                   up(my - y);
  698.             }else{
  699.                if (x != mx || y != my){
  700.                   apri2buf("\x1b[%d;%dH", my=y, mx=x); 
  701.                }
  702.             }
  703.          }
  704.       }
  705.    }
  706. }
  707. */
  708.  
  709.  
  710. /*
  711. void forward(int n,int spaties)   /* checken: gaat niet voorbij EOL */
  712. {                                 /* als geen spaties: n < x-mx     */
  713.    register int tel;
  714.  
  715. /* if (n < 5 || spaties != 0)  */
  716.  
  717.    if (n < 0 || spaties != 0)      /* problems bij achtergrond kleur */
  718.       for (tel=0; tel<n; tel++)
  719.          apri2buf(" ");
  720.    else
  721.       if (n == 1) apri2buf("\x1b[C");
  722.       else        apri2buf("\x1b[%dC",n);
  723.  
  724.    mx += n;
  725.    if (mx > xmax)   mx = xmax;
  726. }
  727. */
  728.  
  729. /*
  730. void backward(int n)
  731. {
  732.    if (n == 1) apri2buf("\x1b[D");
  733.    else        apri2buf("\x1b[%dD",n);
  734.    mx -= n;
  735.    if (mx < 1)   mx = 1;
  736. }
  737. */
  738.  
  739. /*
  740. void down(int n)
  741. {
  742.    if (n == 1) apri2buf("\x1b[B");
  743.    else        apri2buf("\x1b[%dB",n);
  744.    my += n;
  745.    if (my > ymax)   my = ymax;
  746. }
  747. */
  748.  
  749. /*
  750. void up(int n)
  751. {
  752.    if (n == 1) apri2buf("\x1b[A");
  753.    else        apri2buf("\x1b[%dA",n);
  754.    my -= n;
  755.    if (my < 1)   my = 1;
  756. }
  757. */
  758.  
  759.  
  760.  
  761. void col(struct DoorIO *p, int fc,int bc)
  762. {
  763.    int high;       /* is de voorgrond color high intensity ?  */
  764.    int h = 0, f = 0, b = 0;
  765.  
  766.    if (fc > 7){           /* gewone of High intensity colors (Bold) */
  767.       high = 1;
  768.       fc = fc + 22;       /* waarde van 30-37 */
  769.    }else{
  770.       high = 0;
  771.       fc = fc + 30;       /* waarde van 30-37 */
  772.    }
  773.  
  774.    if (bc > 7) bc += 32;  /* waarde van 40-47 */
  775.           else bc += 40;
  776.  
  777.    if (p->mhigh != high)   h = 1;
  778.    if (p->mfc   != fc  )   f = 1;
  779.    if (p->mbc   != bc  )   b = 1;
  780.  
  781.    /* stel mfc=fc en mbc=bc en mhigh!=high dan kleurverandering !! */
  782.  
  783.        /* als 2 kleuren veranderen of de 0m code moet worden   */
  784.        /* gegeven (intensiteit verandering met low intensity)  */
  785.        /* dan beide kleuren veranderen                         */
  786.  
  787.    if ( f || b || h ){         /* iets veranderen  ?*/
  788.       apri2buf("\x1b[");
  789.       if (( f && b ) || ( b && h ) || ( high == 0 && h )){  /* beide kleuren  ?*/
  790.          if ( h ){
  791.             apri2buf("%d;", p->mhigh = high); 
  792.          }
  793.          apri2buf("%d;%dm", p->mfc = fc, p->mbc = bc);
  794.       }else{                           /* anders 1 kleur veranderen */
  795.          if ( f || h ){                /* voorgrond kleur   */
  796.             if ( h ){                  /* indien voorgrond en intensiteit    */
  797.                apri2buf("1;");         /* verandering geef de 1m (low int.)  */
  798.                p->mhigh = 1;
  799.             }
  800.             apri2buf("%dm", p->mfc = fc);
  801.          }else{
  802.             apri2buf("%dm", p->mbc = bc);        /* achtergrond kleur  */
  803.          }
  804.       }
  805.    }
  806. }
  807.  
  808. void fcol(struct DoorIO *p, int fc)
  809. {
  810.    int high;       /* is de voorgrond color high intensity ?  */
  811.    /* int oc; */   /* De output color (30-37) */
  812.  
  813.    if (fc > 7){         /* gewone of High intensity colors (Bold) */
  814.       high = 1;
  815.       fc = fc + 22;     /* waarde van 30-37 */
  816.    }else{
  817.       high = 0;
  818.       fc = fc + 30;     /* waarde van 30-37 */
  819.    }
  820.  
  821.    /* stel mfc=fc en mbc=bc en mhigh!=high dan kleurverandering !! */
  822.  
  823.    if (p->mfc != fc || p->mhigh != high){     /* iets veranderen ?*/
  824.       apri2buf("\x1b[");
  825.       if (high == 0){
  826.          if (p->mhigh != high){      /* als int. verandering en lage int. */
  827.             apri2buf("0;%d;",p->mbc);  /* dan beide kleuren uitgeven  */
  828.             p->mhigh = 0;            /* maar eerst intensiteit code */
  829.          }
  830.          apri2buf("%dm", p->mfc = fc);
  831.       }else{
  832.          if (p->mhigh != high){      /* anders alleen voorgrond kleur    */
  833.             apri2buf("1;");         /* en indien nodig bold code geven  */
  834.             p->mhigh = 1;
  835.          }
  836.          apri2buf("%dm", p->mfc = fc);
  837.       }
  838.    }
  839. }
  840.  
  841. void bcol(struct DoorIO *p, int bc)
  842. {
  843.    if (bc > 7)           /*  if high. int color         */
  844.       bc = bc + 32;      /*  nie goed met 8 verlagen    */
  845.    else
  846.       bc = bc + 40;      /*  background color is 40-47  */
  847.    
  848.    if (p->mbc != bc){       /* moet Bkleur verandert ?     */
  849.       apri2buf("\x1b[%dm", p->mbc = bc);
  850.    }
  851. }
  852.  
  853. void atr(struct DoorIO *p, int atr)       /* attribute veranderen, geen invloed op kleur */
  854. {
  855.    apri2buf("\x1b[%d",atr); 
  856.    if (atr == 0){              /* als geen atribuut dan verandert kleur */
  857.       if (p->mhigh == 1)          /* esc[0;1;[mfc];[mbc]m  */
  858.          apri2buf(";1");
  859.       apri2buf(";%d;%d" ,p->mfc ,p->mbc );
  860.    }
  861.    apri2buf("m");
  862. }
  863.  
  864. void norm(struct DoorIO *p)        /* alle atributes uit, kleuren normaal */
  865. {                      /* kleuren: grijs op zwart              */
  866.    apri2buf("\x1b[0m");
  867.    p->mfc   = 37;
  868.    p->mbc   = 40;
  869.    p->mhigh =  0;
  870. }
  871.  
  872. void cls(struct DoorIO *p)     /* cls en cursor home (home mandatory!!) */
  873. {
  874.    apri2buf("\x1b[H\x1b[J");         /* official ansi , clear screen en */
  875.    p->my = p->mx = 1;                 /* cursor op home positie */
  876. }
  877.  
  878.  
  879.  
  880.  
  881. /*===( Simple ANSI code )=================================*/
  882.  
  883. /*
  884. void col(int fc,int bc)
  885. {
  886.    if (fc > 7){
  887.       printf("\x1b[1;%d;%dm", fc + 22 , bc + 40);
  888.    }else{
  889.       printf("\x1b[0;%d;%dm", fc + 30 , bc + 40);
  890.    }
  891. }
  892.  
  893. void cursxy(int x,int y)
  894. {
  895.    if (y == 1 && x == 1){
  896.       printf("\x1b[H"); 
  897.    }else{
  898.       printf("\x1b[%d;%dH", y, x); 
  899.    }
  900. }
  901.  
  902. void fcol(int fc)
  903. {
  904.    if (fc > 7){
  905.       printf("\x1b[1;%dm", fc + 22);
  906.    }else{
  907.       printf("\x1b[0;%dm", fc + 30);
  908.    }
  909. }
  910.  
  911. void bcol(int bc)
  912. {
  913.    printf("\x1b[%dm", bc + 40);
  914. }
  915.  
  916. void atr(int atr)
  917. {
  918.    printf("\x1b[%dm", atr);
  919. }
  920.  
  921. void norm(void)
  922. {
  923.    printf("\x1b[0m");
  924. }
  925.  
  926. void cls(void)
  927. {
  928.    printf("\x1b[H\x1b[J"); 
  929. }
  930.  
  931. */
  932.