home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d523 / serlib.lha / SerLib / Examples / Lattice / Antrag / antrag.c < prev    next >
C/C++ Source or Header  |  1991-08-05  |  31KB  |  1,246 lines

  1. /**********************************************************************\
  2.  *                               Antrag                               *
  3.  *                                                                    *
  4.  *                         © 1991 G. Glendown                         *
  5.  *                                                                    *
  6.  * `Antrag' ist ein externes Programm für das hervorragende Mailbox-  *
  7.  *Programm Euromail. Hiermit ist -für Ansi und VT100-User- eine etwas *
  8.  *         komfortablere Eintragung in der Userliste möglich.         *
  9.  *                                                                    *
  10.  *  Außerdem soll `Antrag' noch als Beispiel für die Verwendung der   *
  11.  *serlib.library dienen. Neben der eigentlichen Verwendung der Library*
  12.  * Funktionen sind noch einige Funktionen implementiert, die für die  *
  13.  *   Programmierung von Online-Games sehr interessant sein können.    *
  14.  *                                                                    *
  15.  *`Antrag' ist Freeware. Der kommerzielle Vertrieb (und dazu zähle ich*
  16.  *nahezu alle deutschen `PD-Händler') ist nur mit meiner schriftlichen*
  17.  *                        Genehmigung erlaubt.                        *
  18. \**********************************************************************/
  19.  
  20. /**********************************************************************\
  21.  *to programmers: if you use part of this program in your program(s), *
  22.  *      I would appreciate a copy of the source & executeable...      *
  23. \**********************************************************************/
  24.  
  25. #define scrdef    NewScreenStructure
  26. #define windef    NewWindowStructure1
  27. #define WINFB    0x01
  28.  
  29. struct NewScreen NewScreenStructure = {
  30.     0,0,640,211,2,0,1,HIRES,CUSTOMSCREEN,NULL,NULL,NULL,NULL};
  31.  
  32. #define NEWSCREENSTRUCTURE NewScreenStructure
  33.  
  34. USHORT Palette[] = {
  35.     0x0000,0x0FFF,0x0888,0x035B};
  36.  
  37. #define PALETTE Palette
  38.  
  39. USHORT chip ImageData1[] = {
  40.     0x0000,0x0000,0x7FFF,0xFE00,0x7FFF,0xFE00,0x7803,0xFE00,
  41.     0x78FF,0xFE00,0x7880,0x3E00,0x7F80,0x3E00,0x7F80,0x3E00,
  42.     0x7FFF,0xFE00,0x7FFF,0xFE00,0xFFFF,0xFE00,0xFFFF,0xFE00,
  43.     0xFFFF,0xFC00,0xF001,0xFC00,0xF001,0xFC00,0xF000,0x1C00,
  44.     0xF07F,0xDC00,0xF07F,0xDC00,0xFF7F,0xDC00,0xFF00,0x1C00,
  45.     0xFFFF,0xFC00,0x0000,0x0000};
  46.  
  47. struct Image Image1 = {
  48.     0,0,23,11,2,ImageData1,0x0003,0x0000,NULL};
  49.  
  50. USHORT chip ImageData2[] = {
  51.     0xFFFF,0xFE00,0xFFFF,0xFC00,0xFFFF,0xFC00,0xF803,0xFC00,
  52.     0xF8FF,0xFC00,0xF882,0x3C00,0xFFFE,0x3C00,0xFF80,0x3C00,
  53.     0xFFFF,0xFC00,0xFFFF,0xFC00,0x0000,0x0000,0x0000,0x0000,
  54.     0x7FFF,0xFE00,0x7001,0xFE00,0x7001,0xFE00,0x7000,0x1E00,
  55.     0x707D,0xDE00,0x7001,0xDE00,0x7F7F,0xDE00,0x7F00,0x1E00,
  56.     0x7FFF,0xFE00,0xFFFF,0xFE00};
  57.  
  58. struct Image Image2 = {
  59.     0,0,23,11,2,ImageData2,0x0003,0x0000,NULL};
  60.  
  61. struct Gadget Gadget1 = {
  62.     NULL,617,0,23,11,GADGHIMAGE+GADGIMAGE,RELVERIFY,BOOLGADGET,
  63.     (APTR)&Image1,(APTR)&Image2,NULL,NULL,NULL,WINFB,NULL};
  64.  
  65. struct NewWindow NewWindowStructure1 = {
  66.     0,0,640,211,0,1,GADGETUP+CLOSEWINDOW+VANILLAKEY,
  67.     BORDERLESS+ACTIVATE+RMBTRAP+NOCAREREFRESH,
  68.     &Gadget1,NULL,NULL,NULL,NULL,5,5,-1,-1,CUSTOMSCREEN};
  69.  
  70. #include <serlib.h>
  71. #include <em-strukturen.h>
  72. #include "antrag.proto"
  73.  
  74. /* return-values of the `GetString'-function */
  75. #define EMPTY    0x01    /* an empty input line */
  76. #define OK        0x02    /* everything OK... */
  77. #define CTRLX    0x03    /* aborted with CTRL-X or CTRL-C */
  78. #define NOCD    0x04    /* carrier lost */
  79. #define NACK    0x05    /* not OK... (not used by GetString) */
  80.  
  81. /* Some definitions for GetString ... */
  82. #define HIDE        (1<<0)            /* Only Echo `*' */
  83. #define ALLOWTABLE    (1<<1)            /* The table contains allowed chars */
  84. #define FORBIDTABLE    (1<<2)            /* The table contains forbidden chars */
  85. #define ALPHA        (1<<3)            /* Allow Alpha-Chars (A-z) */
  86. #define GERMAN        (1<<4)            /* Allow german chars (äöüÄÖÜß) */
  87. #define NUM            (1<<5)            /* Allow numbers */
  88. #define OTHER        (1<<6)            /* Other ASCII-Chars */
  89. #define SPACES        (1<<7)            /* Allow Spaces */
  90. #define ALLOWEMPTY    (1<<8)            /* Allow empty string */
  91. #define KEYS        (ALPHA|NUM|OTHER)
  92.  
  93. /* Some character definitions */
  94. #define NORMAL    0x01
  95. #define BACKSP    0x02
  96. #define RETURNCHAR    0x03
  97. #define BREAKCHAR    0x04
  98. #define IGNORE    0x05
  99. #define SPACE    0x06
  100.  
  101. static char CLS[]={12,27,"[2J"};
  102. static char BEEP[]={7,0};
  103. static char DLL[]={27,"[2K"};
  104. static char ESC[]={27,'[',0};
  105. static char space[]={"                                                                                "};
  106. static char SP[]={" "};
  107. struct SerLibBase *SerLibBase;
  108. struct SerStatus ss;
  109. struct SerLibData    *sld;
  110. char buf[128],temp[128],tmp[128];
  111. struct timerequest *tr=NULL;
  112. struct MsgPort    *tport;
  113. struct Message    *tmsg;
  114. struct timeval    tv;
  115.  
  116. char cl[2][128];
  117. int cx[2],cy[2],bw[2],lc[2],cpos[2],con=1,CORRECT;
  118. ULONG baud;
  119.  
  120. struct    Prefer ep,*ep2;
  121.  
  122. BOOL Ansi,LASTCR;
  123. char BBSBaud[32],BBSUser[80],BBSStatus[32],BBSOnline[32],BBSRest[32],
  124.      BBSDev[32],BBSTerm[32];
  125.  
  126. struct IntuitionBase *IntuitionBase;
  127. struct IntuiMessage *msg;
  128. LONG class;
  129. int code,line;
  130.  
  131. /*#define CheckCD(a)    (1==1)*/
  132.  
  133. struct GfxBase *GfxBase;
  134.  
  135. struct ViewPort *vp;
  136. struct RastPort *rp;
  137. struct Screen *scr=NULL;
  138. struct Window *win=NULL;
  139.  
  140. int ser;
  141.  
  142. char MyTable[]={    "\tRazAZ!?__", 0 };
  143.  
  144. struct Usereintrag *user=NULL;
  145. struct NewUser {
  146.     UBYTE Uname[16];
  147.     UBYTE Passw[9];
  148.     UBYTE Name[20];
  149.     UBYTE Vorname[20];
  150.     UBYTE Strasse[25];
  151.     UBYTE PlzOrt[25];
  152.     UBYTE Telefon[25];
  153.     UBYTE Rechner[9];
  154.     UBYTE Terminal[9];
  155.     UBYTE Sprache[9];
  156. } newuser;
  157.  
  158. long usersize;
  159. int numuser;
  160.  
  161. char protokoll[128],newusf[128];
  162.  
  163. char comp[][9]={"-","A1000","A500","A2000","A2500","A3000","Atari ST",
  164.                 "Atari TT","PC/XT/AT","Unix"};
  165. char term[][9]={"TTY","ANSI","VT-100"};
  166.  
  167. char    SERDEVNAME[]={"serial.device\0<------------------>"};
  168. int        SERUNIT;
  169. ULONG    BBS_FLAGS;
  170.  
  171. void main(long argc,char *argv[])
  172. {
  173. ULONG rw;
  174. int t;
  175. FILE *f;
  176.     SERUNIT=0;
  177.     BBS_FLAGS=0L;
  178.     ScanData();
  179.     OpenStuff();
  180.     CORRECT=0;
  181.     if (con==0) {
  182.         if (argc) {
  183.             if (argv[1][0]=='B')
  184.                 baud=atol(&(argv[1][1]));
  185.         }
  186.         if (!(sld=OpenSerial(SERDEVNAME,SERUNIT,baud,8,1,(ULONG)(BBS_FLAGS|SERF_SHARED))))
  187.             printf("Keine Verbindung zum Modem möglich!\n"),ex();
  188.         ChangeData(sld,baud,8,1,(ULONG)(BBS_FLAGS|SERF_SHARED));
  189.     }
  190.     SendString(CLS);
  191.     PositionText(32,0,"User-Antrag");
  192.     PositionText(32,1,"-----------");
  193.     PositionText(0,3,"Die Anmelde-Prozedur kann jederzeit durch Eingabe von CTRL-X abgebrochen");
  194.     PositionText(0,4,"werden...");
  195.  
  196.  
  197. enteruname:
  198.     line=6;
  199.     PositionText(0,line,"1. Gewuenschter Username:                                 ");
  200. nameloop:
  201.     rw=GetString(temp,15,ALLOWTABLE,MyTable,win,27,line);
  202.     switch (rw) {
  203.         case OK:
  204.             break;
  205.         case CTRLX:
  206.             if (AskAbort(win,"Antrag abbrechen ?")!=NACK)
  207.                 ex();
  208.             else goto nameloop;
  209.             break;
  210.         case NOCD:
  211.             ex();
  212.     }
  213.     for (t=0;t<numuser;t++) {
  214.         if (!stricmp(user[t].Uname,temp)) {
  215.             PositionText(27,line,"Username bereits vorhanden!");
  216.             Delay(50L);
  217.             PositionText(27,line,"                           ");
  218.             goto nameloop;
  219.         }
  220.     }
  221.  
  222.     strncpy(newuser.Uname,temp,16);
  223.     if (CORRECT)    goto correct;
  224.     line=7;
  225.  
  226. pwloop1:
  227.     PositionText(0,line,"2. Bitte Passwort waehlen:                            ");
  228.     rw=GetString(temp,8,KEYS|HIDE|ALLOWEMPTY,NULL,win,27,line);
  229.     switch (rw) {
  230.         case OK:
  231.             break;
  232.         case CTRLX:
  233.             if (AskAbort(win,"Antrag beenden ?")!=NACK)
  234.                 ex();
  235.             else goto pwloop1;
  236.             break;
  237.         case NOCD:
  238.             ex();
  239.     }
  240.     if (strlen(temp)<3) {
  241.         PositionText(10,24,"Passwort zu kurz! Eingabe wiederholen!");
  242.         Delay(50L);
  243.         PositionText(10,24,"                                      ");
  244.         goto pwloop1;
  245.     }
  246. pwloop2:
  247.     PositionText(0,line+1,"   Passwort wiederholen:                             ");
  248.     rw=GetString(tmp,8,KEYS|HIDE,NULL,win,27,line+1);
  249.     switch (rw) {
  250.         case OK:
  251.             break;
  252.         case CTRLX:
  253.             if (AskAbort(win,"Antrag beenden ?")!=NACK)
  254.                 ex();
  255.             else goto pwloop2;
  256.             break;
  257.         case NOCD:
  258.             ex();
  259.     }
  260.     if (stricmp(tmp,temp)) {
  261.         PositionText(10,24,"Passworte stimmen nicht! Eingabe wiederholen!");
  262.         Delay(50L);
  263.         PositionText(10,24,"                                             ");
  264.         PositionText(0,line+1,"                                             ");
  265.         goto pwloop1;
  266.     }
  267.     strncpy(newuser.Passw,tmp,9);
  268.  
  269.     if (CORRECT) {
  270.         PositionText(0,line,"                                             ");
  271.         PositionText(0,line+1,"                                            ");
  272.         goto correct;
  273.     }
  274.     else
  275.         PositionText(0,line,"2. Passwort                                  ");
  276.  
  277. entervname:
  278.     line=8;
  279.     PositionText(0,line,"3. Vorname :                                             ");
  280. vnameloop:
  281.     rw=GetString(temp,19,KEYS|SPACES|GERMAN|ALLOWEMPTY,NULL,win,15,line);
  282.     switch (rw) {
  283.         case OK:
  284.         case EMPTY:
  285.             break;
  286.         case CTRLX:
  287.             if (AskAbort(win,"Antrag abbrechen ?")!=NACK)
  288.                 ex();
  289.             else goto vnameloop;
  290.             break;
  291.         case NOCD:
  292.             ex();
  293.     }
  294.     strcpy(newuser.Vorname,temp);
  295.     if (CORRECT)    goto checkname;
  296.  
  297. entername:
  298.     line=9;
  299.     PositionText(0,line,"4. Nachname:                                             ");
  300. nnameloop:
  301.     rw=GetString(temp,19,KEYS|SPACES|GERMAN,NULL,win,15,line);
  302.     switch (rw) {
  303.         case OK:
  304.             break;
  305.         case CTRLX:
  306.             if (AskAbort(win,"Antrag abbrechen ?")!=NACK)
  307.                 ex();
  308.             else goto nnameloop;
  309.             break;
  310.         case NOCD:
  311.             ex();
  312.     }
  313.     strcpy(newuser.Name,temp);
  314. checkname:
  315.     for (t=0;t<numuser;t++) {
  316.         if (!stricmp(user[t].Name,newuser.Name)) {
  317.             if (!stricmp(user[t].Vorname,newuser.Vorname)) {
  318.                 sprintf(temp,"`%s %s' hat schon einen Account.",user[t].Vorname,user[t].Name);
  319.                 PositionText(10,22,temp);
  320.                 t=AskAbort(win,"Antrag beenden ?");
  321.                 PositionText(10,22,"                                                                  ");
  322.                 if (t!=NACK) ex();
  323.                 else t=numuser;
  324.             }
  325.         }
  326.     }
  327.     if (CORRECT)    goto correct;
  328.  
  329. enterstreet:
  330.     line=10;
  331.     PositionText(0,line,"5. Strasse :                                              ");
  332. streetloop:
  333.     rw=GetString(temp,24,KEYS|SPACES|GERMAN|ALLOWEMPTY,NULL,win,15,line);
  334.     switch (rw) {
  335.         case OK:
  336.             break;
  337.         case CTRLX:
  338.             if (AskAbort(win,"Antrag abbrechen ?")!=NACK)
  339.                 ex();
  340.             else goto streetloop;
  341.             break;
  342.         case NOCD:
  343.             ex();
  344.     }
  345.     strcpy(newuser.Strasse,temp);
  346.     if (CORRECT) goto correct;
  347.  
  348. entertown:
  349.     line=11;
  350.     PositionText(0,line,"6. PLZ ORT :                                            ");
  351. placeloop:
  352.     rw=GetString(temp,24,KEYS|SPACES|GERMAN,NULL,win,15,line);
  353.     switch (rw) {
  354.         case OK:
  355.             break;
  356.         case CTRLX:
  357.             if (AskAbort(win,"Antrag abbrechen ?")!=NACK)
  358.                 ex();
  359.             else goto placeloop;
  360.             break;
  361.         case NOCD:
  362.             ex();
  363.     }
  364.     strcpy(newuser.PlzOrt,temp);
  365.     if (CORRECT)    goto correct;
  366.  
  367. entertel:
  368.     line=12;
  369.     PositionText(0,line,"7. Telefon :                                             ");
  370. telloop:
  371.     rw=GetString(temp,24,ALLOWTABLE,"01234567890()/-+ ",win,15,line);
  372.     switch (rw) {
  373.         case OK:
  374.             break;
  375.         case CTRLX:
  376.             if (AskAbort(win,"Antrag abbrechen ?")!=NACK)
  377.                 ex();
  378.             else goto telloop;
  379.             break;
  380.         case NOCD:
  381.             ex();
  382.     }
  383.     strcpy(newuser.Telefon,temp);
  384.     if (CORRECT)    goto correct;
  385.     line=13;
  386.  
  387. entercomp:
  388.     PositionText(0,line,"-1- Amiga 1000   -2- Amiga 500    -3- Amiga 2000");
  389.     PositionText(0,line+1,"-4- Amiga 2500   -5- Amiga 3000   -6- Atari ST");
  390.     PositionText(0,line+2,"-7- Atari TT     -8- PC/XT/AT     -9- Unix-Rechner");
  391.     PositionText(0,line+3,"-0- andere");
  392. comploop:
  393.     PositionText(0,line+4,"Bitte waehlen:     ");
  394.     rw=GetString(temp,1,NUM,NULL,win,16,line+4);
  395.     switch (rw) {
  396.         case OK:
  397.             if (atoi(temp)>9)
  398.                 goto comploop;
  399.             break;
  400.         case CTRLX:
  401.             if (AskAbort(win,"Antrag abbrechen ?")!=NACK)
  402.                 ex();
  403.             else goto comploop;
  404.             break;
  405.         case NOCD:
  406.             ex();
  407.     }
  408.     strcpy(newuser.Rechner,comp[atoi(temp)]);
  409.     for (t=0;t<5;t++)
  410.         PositionText(0,line+t,"                                                               ");
  411.     PositionText(0,line,"8. Computer: ");
  412.     PositionText(15,line,newuser.Rechner);
  413.     if (CORRECT)    goto correct;
  414.     line=14;
  415.  
  416. enterterm:
  417.     PositionText(0,line,"-0- TTY     -1- ANSI     -2- VT-100");
  418. termloop:
  419.     PositionText(0,line+1,"Bitte Terminal-Emulation waehlen:     ");
  420.     rw=GetString(temp,1,ALLOWTABLE,"012",win,35,line+1);
  421.     switch (rw) {
  422.         case OK:
  423.             break;
  424.         case CTRLX:
  425.             if (AskAbort(win,"Antrag abbrechen ?")!=NACK)
  426.                 ex();
  427.             else goto termloop;
  428.             break;
  429.         case NOCD:
  430.             ex();
  431.     }
  432.     strcpy(newuser.Terminal,term[atoi(temp)]);
  433.     PositionText(0,line,"9. Terminal:                                       ");
  434.     PositionText(0,line+1,"                                            ");
  435.     PositionText(15,line,newuser.Terminal);
  436.     if (CORRECT)    goto correct;
  437.  
  438. finalquestion:
  439.     PositionText(0,16,"Eingaben Korrekt (J/n/q) ?");
  440.     rw=GetString(temp,1,ALLOWTABLE|ALLOWEMPTY,"JNQjnq",win,28,16);
  441.     switch (rw) {
  442.         case OK:
  443.             *temp=toupper(*temp);
  444.             switch (*temp) {
  445.                 case 'J':
  446.                     goto finished;
  447.                     break;
  448.                 case 'Q':
  449.                     if (AskAbort(win,"Antrag abbrechen ?")!=NACK)
  450.                         ex();
  451.                     else goto finalquestion;
  452.                     break;
  453.                 case 'N':
  454.                     goto correct;
  455.                     break;
  456.             }
  457.             break;
  458.         case CTRLX:
  459.             if (AskAbort(win,"Antrag abbrechen ?")!=NACK)
  460.                 ex();
  461.             else goto finalquestion;
  462.             break;
  463.         case EMPTY:
  464.             goto finished;
  465.             break;
  466.         case NOCD:
  467.             ex();
  468.     }
  469.  
  470. finished:
  471.     if (f=fopen(newusf,"w")) {
  472.         fprintf(f,"User:  %s\nPW:    %s\n",newuser.Uname,newuser.Passw);
  473.         fprintf(f,"Name:  %s %s\n",newuser.Vorname,newuser.Name);
  474.         fprintf(f,"Str.:  %s\nOrt:   %s\n",newuser.Strasse,newuser.PlzOrt);
  475.         fprintf(f,"Tel.:  %s\nComp:  %s\n",newuser.Telefon,newuser.Rechner);
  476.         fprintf(f,"Terminal: %s\nSprache: %s\n",newuser.Terminal,newuser.Sprache);
  477.         fprintf(f,"Baudrate des Anrufs: %s\n",BBSBaud);
  478.         fclose(f);
  479.     }
  480.     else {
  481.         ToProto("Konnte Ausgabefile nicht öffnen!");
  482.         printf("Achtung! Systemfehler! Bitte den Sysop benachrichtigen!\n");
  483.     }
  484.     newusf[0]='\0';
  485.     PositionText(0,23,"Antrag abgesandt...");
  486.     Delay(100L);
  487.     ex();
  488.  
  489. correct:
  490.     if (CORRECT) {
  491.         PositionText(15,13,"          ");
  492.         PositionText(15,14,"          ");
  493.         PositionText(15,14,newuser.Terminal);
  494.         PositionText(15,13,newuser.Rechner);
  495.     }
  496.     PositionText(0,16,"Welche Zeile ändern ? (0=Fertig)");
  497. correct2:
  498.     rw=GetString(temp,1,ALLOWTABLE,"\tR09",win,34,16);
  499.     switch (rw) {
  500.         case OK:
  501.             break;
  502.         case CTRLX:
  503.             if (AskAbort(win,"Antrag abbrechen ?")!=NACK)
  504.                 ex();
  505.             else goto correct2;
  506.             break;
  507.         case NOCD:
  508.             ex();
  509.     }
  510.     PositionText(0,16,"                                    ");
  511.     CORRECT=1;
  512.     switch (atoi(temp)) {
  513.         case 0:
  514.             CORRECT=0;
  515.             goto finalquestion;
  516.             break;
  517.         case 1:
  518.             goto enteruname;
  519.             break;
  520.         case 2:
  521.             line=17;
  522.             goto pwloop1;
  523.             break;
  524.         case 3:
  525.             goto entervname;
  526.             break;
  527.         case 4:
  528.             goto entername;
  529.             break;
  530.         case 5:
  531.             goto enterstreet;
  532.             break;
  533.         case 6:
  534.             goto entertown;
  535.             break;
  536.         case 7:
  537.             goto entertel;
  538.             break;
  539.         case 8:
  540.             line=16;
  541.             goto entercomp;
  542.             break;
  543.         case 9:
  544.             line=16;
  545.             goto enterterm;
  546.             break;
  547.     }
  548. }
  549.  
  550. /**********************************************************************\
  551.  *                              AskAbort                              *
  552.  *                                                                    *
  553.  *      Ask the user if he really wants to abort what he did...       *
  554. \**********************************************************************/
  555.  
  556. ULONG AskAbort(struct Window *win,char *txt)
  557. {
  558. ULONG mask,rw,len,result;
  559. int l;
  560.     mask=((1L<<(win->UserPort->mp_SigBit))|(1L<<(tport->mp_SigBit)));
  561.     PositionText(10,23,txt);
  562.     l=11+strlen(txt);
  563.     rw=NOCD;
  564. loop1:
  565.     DoTime(tr,20);
  566.     buf[0]='\0';
  567.     buf[1]='\0';
  568.     if (!con) {
  569.         RecvSer(sld,buf,1);
  570.         result=WaitSer(sld,mask);
  571.     }
  572.     else
  573.         result=Wait(mask);
  574.     Disable();
  575.     if (!CheckIO((struct IORequest *)tr)) {
  576.         AbortIO((struct IORequest *)tr);
  577.         WaitIO((struct IORequest *)tr);
  578.     }
  579.     if (!con) {
  580.         if (!CheckIOSer(sld)) {
  581.             AbortIOSer(sld,ABORT_RECV);
  582.             WaitSer(sld,0L);
  583.         }
  584.     }
  585.     Enable();
  586.     if (!con) {
  587.         if (!(CheckCD(sld))) return(NOCD);
  588.         len=strlen(buf);
  589.         if (len) goto gotachar;
  590.         if (SerBuffer(sld)>0) {
  591.             len=ReadSer(sld,buf,1);
  592.             if (len) {
  593. gotachar:
  594.                 rw=NOCD;
  595.                 switch (*buf) {
  596.                     case 'J':
  597.                     case 'j':
  598.                         rw=OK;
  599.                         break;
  600.                     case 'N':
  601.                     case 'n':
  602.                         rw=NACK;
  603.                         break;
  604.                     case 3:
  605.                     case 24:
  606.                         rw=CTRLX;
  607.                         break;
  608.                     case 13: 
  609.                     case 10:
  610.                         rw=EMPTY;
  611.                         break;
  612.                     default:
  613.                         Flash(scr);
  614.                 }
  615.                 EmptyBuf();
  616.             }
  617.         }
  618.     }
  619.     if (msg=(struct IntuiMessage *)GetMsg(win->UserPort)) {
  620.         if (msg->Class==VANILLAKEY) {
  621.             switch (msg->Code) {
  622.                 case 'J':
  623.                 case 'j':
  624.                     rw=OK;
  625.                     break;
  626.                 case 'N':
  627.                 case 'n':
  628.                     rw=NACK;
  629.                     break;
  630.                 case 3:
  631.                 case 24:
  632.                     rw=CTRLX;
  633.                     break;
  634.                 case 13: 
  635.                 case 10:
  636.                     rw=EMPTY;
  637.                     break;
  638.                 default:
  639.                     Flash(scr);
  640.             }
  641.         }
  642.         while (msg) {
  643.             ReplyMsg((struct Message *)msg);
  644.             msg=(struct IntuiMessage *)GetMsg(win->UserPort);
  645.         }
  646.     }
  647.     if (rw!=NOCD) {
  648.         PositionText(10,23,"                                     ");
  649.         return(rw);
  650.     }
  651.     else goto loop1;
  652. }
  653.  
  654. /**********************************************************************\
  655.  *                             GetString                              *
  656. \**********************************************************************/
  657. /*
  658. Now, this one's a real jewel. You have LOTS of possibilities with this
  659. function. Let's do the params one by one...
  660.  
  661. txt - pointer to the text buffer, which is
  662. mlen  bytes long. Any inputs that would lead to a longer string are
  663.       ignored.
  664. flags With this ULONG, you define how GetString will behave. Currently, the
  665.       following flag types are understood:
  666.         HIDE        - characters typed are echoed as `*' (useful for PW,
  667.                       etc.)
  668.         ALLOWTABLE    - the table-pointer points to a set of characters that
  669.                       are allowed
  670.         FORBIDTABLE    - the table-pointer points to a set of characters that
  671.                       are forbidden
  672.         ALPHA        - allow all alpha-chars (a-z, A-Z)
  673.         GERMAN        - allow german chars (äöüÄÖÜß)
  674.         NUM            - allow numbers
  675.         OTHER        - allow other ASCII-chars
  676.         SPACES        - allow Space and TAB (Tab is converted to a Space)
  677.         ALLOWEMPTY    - permit an empty input
  678.         KEYS        - Kombination of ALPHA, NUM and OTHER
  679.       Just about the only thing that is missing right now is an automatic
  680.       conversion of PC or Atari special characters (äöü...)
  681. table a table of characters that are either allowed or forbidden
  682.       additionally to the chars already defined by the flag-bits.
  683.       This one is pretty smart two. You can have two different types of
  684.       tables: either one that explicitely contains every characters, or a
  685.       range of characters (the latter being specified by the table starting
  686.       with the two chars `\t' and `R'.
  687.       So, instead of writing:
  688.       "1234567890"
  689.       to include all numbers, you could also write:
  690.       "\tR09"
  691.       As you cannot mix the two table kinds, to define just a single
  692.       character in the range-table, just duplicate the char:
  693.       "\tR09--//"
  694.       This table will allow all numbers, plus the chars `-' and '/'.
  695.       As noted before, a table can either be an `Allowtable' or a
  696.       `Forbidtable'. No matter what kind it is, it will be looked at first.
  697.       So, if you haven't set the Flag `SPACES' in the Flags-field, and have
  698.       an allow table that includes a Space, it will be returned as a valid
  699.       char. On the other hand, by specifying a forbid table, you could,
  700.       e.g., forbid the use of the chars `g' and `h' by specifying a
  701.       apropriate table and setting the FORBIDTABLE flag, plus the other
  702.       flags you might need. Now, the user can not enter a `g' or `h' anymore.
  703. win - a pointer to a Window-structure, in which the output is to be
  704.       performed.
  705. posx, position of the input `window'. Make sure that posx+mlen doesn't
  706. posy  exceed the size of the window (remember there is a cursor displayed,
  707.       so the maximum size useable for a 640-screen would be 78)
  708. */
  709.  
  710. ULONG GetString(txt,mlen,flags,table,win,posx,posy)
  711. char *txt;
  712. int mlen;
  713. ULONG flags;
  714. char *table;
  715. struct Window *win;
  716. int posx,posy;
  717. {
  718. ULONG mask,result,_len,t,len=0;
  719. int type;
  720.     LASTCR=FALSE;
  721.     mask=((1L<<(win->UserPort->mp_SigBit))|(1L<<(tport->mp_SigBit)));
  722.     PositionChar(posx,posy,'_');
  723. loop:
  724.     buf[0]='\0';
  725.     buf[1]='\0';
  726.     DoTime(tr,50L);    /* 1 Sekunde timeout */
  727.     if (!con) {
  728.         RecvSer(sld,buf,1);
  729.         result=WaitSer(sld,mask);
  730.     }
  731.     else
  732.         result=Wait(mask);
  733.     Disable();
  734.     if (!CheckIO((struct IORequest *)tr)) {
  735.         AbortIO((struct IORequest *)tr);
  736.         WaitIO((struct IORequest *)tr);
  737.     }
  738.     if (!con) {
  739.         if (!CheckIOSer(sld)) {
  740.             AbortIOSer(sld,ABORT_RECV);
  741.             WaitSer(sld,0L);
  742.         }
  743.     }
  744.     Enable();
  745.     if (!con) {
  746.         if (!CheckCD(sld)) return(NOCD);
  747.         if (_len=strlen(buf))
  748.             goto gotitagain;
  749.         if (SerBuffer(sld)>0) {
  750.             _len=ReadSer(sld,buf,64);
  751. gotitagain:
  752.             for (t=0;t<_len;t++) {
  753.                 if (type=CheckChar(buf[t],flags,table)) {
  754.                     switch (type) {
  755.                         case NORMAL:
  756.                             if (len<mlen) {
  757.                                 if (flags&HIDE)
  758.                                     PositionChar(posx+len,posy,'*');
  759.                                 else
  760.                                     PositionChar(posx+len,posy,buf[t]);
  761.                                 txt[len]=buf[t];
  762.                                 len++;
  763.                                 PositionChar(posx+len,posy,'_');
  764.                             }
  765.                             else
  766.                                 Flash(scr);
  767.                             break;
  768.                         case SPACE:
  769.                             if (len<mlen) {
  770.                                 if (flags&HIDE)
  771.                                     PositionChar(posx+len,posy,'*');
  772.                                 else
  773.                                     PositionChar(posx+len,posy,' ');
  774.                                 txt[len]=' ';
  775.                                 len++;
  776.                                 PositionChar(posx+len,posy,'_');
  777.                             }
  778.                             else
  779.                                 Flash(scr);
  780.                             break;
  781.                         case BACKSP:
  782.                             if (len) {
  783.                                 PositionText(posx+len-1,posy,"_ ");
  784.                                 len--;
  785.                                 txt[len]='\0';
  786.                             }
  787.                             else
  788.                                 Flash(scr);
  789.                             break;
  790.                         case RETURNCHAR:
  791.                             EmptyBuf();
  792.                             PositionChar(posx+len,posy,' ');
  793.                             txt[len]='\0';
  794.                             if (len>0) {
  795.                                 return(OK);
  796.                             }
  797.                             else {
  798.                                 if (flags&ALLOWEMPTY)
  799.                                     return(EMPTY);
  800.                                 else {
  801.                                     PositionChar(posx+len,posy,'_');
  802.                                     Flash(scr);
  803.                                 }
  804.                             }
  805.                             break;
  806.                         case BREAKCHAR:
  807.                             EmptyBuf();
  808.                             PositionChar(posx+len,posy,' ');
  809.                             txt[0]='\0';
  810.                             return(CTRLX);
  811.                         case IGNORE:
  812.                             Flash(scr);
  813.                             break;
  814.                     }
  815.                 }
  816.             }
  817.         }
  818.     }
  819.     msg=(struct IntuiMessage *)GetMsg(win->UserPort);
  820.     while (msg) {
  821.         class=msg->Class;
  822.         code=msg->Code;
  823.         switch (class) {
  824.             case VANILLAKEY:
  825.                 if (type=CheckChar(code,flags,table)) {
  826.                     switch (type) {
  827.                         case NORMAL:
  828.                             if (len<mlen) {
  829.                                 if (flags&HIDE)
  830.                                     PositionChar(posx+len,posy,'*');
  831.                                 else
  832.                                     PositionChar(posx+len,posy,code);
  833.                                 txt[len]=code;
  834.                                 len++;
  835.                                 PositionChar(posx+len,posy,'_');
  836.                             }
  837.                             else
  838.                                 Flash(scr);
  839.                             break;
  840.                         case SPACE:
  841.                             if (len<mlen) {
  842.                                 if (flags&HIDE)
  843.                                     PositionChar(posx+len,posy,'*');
  844.                                 else
  845.                                     PositionChar(posx+len,posy,' ');
  846.                                 txt[len]=' ';
  847.                                 len++;
  848.                                 PositionChar(posx+len,posy,'_');
  849.                             }
  850.                             else
  851.                                 Flash(scr);
  852.                             break;
  853.                         case BACKSP:
  854.                             if (len)
  855.                                 PositionText(posx+len-1,posy,"_ "),
  856.                                 len--,
  857.                                 txt[len]='\0';
  858.                             else
  859.                                 Flash(scr);
  860.                             break;
  861.                         case RETURNCHAR:
  862.                             EmptyBuf();
  863.                             txt[len]='\0';
  864.                             PositionChar(posx+len,posy,' ');
  865.                             if (len)
  866.                                 return(OK);
  867.                             else
  868.                                 if (flags&ALLOWEMPTY)
  869.                                     return(EMPTY);
  870.                                 else
  871.                                     PositionChar(posx+len,posy,'_'),
  872.                                     Flash(scr);
  873.                             break;
  874.                         case BREAKCHAR:
  875.                             EmptyBuf();
  876.                             txt[0]='\0';
  877.                             PositionChar(posx+len,posy,' ');
  878.                             return(CTRLX);
  879.                         case IGNORE:
  880.                             Flash(scr);
  881.                             break;
  882.                     }
  883.                 }
  884.                 break;
  885.         }
  886.         ReplyMsg((struct Message *)msg);
  887.         msg=(struct IntuiMessage *)GetMsg(win->UserPort);
  888.     }
  889.     goto loop;
  890. }
  891.  
  892. void Flash(struct Screen *scr)
  893. {
  894.     DisplayBeep(scr);
  895.     SendString(BEEP);
  896. }
  897.  
  898. char AlphaTable[]={    "\tRazAZ", 0 };
  899. char NumTable[]={     "\tR09", 0};
  900. char GermanTable[]={"äöüÄÖÜß",0};
  901. char OtherTable[]={    "\tR!/:?[`{~",0};
  902.  
  903. /**********************************************************************\
  904.  *                             CheckChar                              *
  905.  *                                                                    *
  906.  *              Checks whether a char is allowed or not               *
  907. \**********************************************************************/
  908.  
  909. ULONG CheckChar(char c,ULONG flags,char *table)
  910. {
  911. BOOL ALLOWED=FALSE;
  912.  
  913.     if (flags&ALLOWTABLE) {
  914.         if (!(InTable(c,table)))
  915.             ALLOWED=FALSE;
  916.         else ALLOWED=TRUE;
  917.     }
  918.     if (flags&FORBIDTABLE) {
  919.         if (InTable(c,table))
  920.             ALLOWED=FALSE;
  921.         else ALLOWED=TRUE;
  922.     }
  923.     if (c==10) {
  924.         if (LASTCR) {
  925.             LASTCR=FALSE;
  926.             return(IGNORE);
  927.         }
  928.         else return(RETURNCHAR);
  929.     }
  930.     if (c==13) {
  931.         LASTCR=TRUE;
  932.         return(RETURNCHAR);
  933.     }
  934.     if (c==8) return(BACKSP);
  935.     if ((c==24)||(c==3))    return(BREAKCHAR);
  936.     if (flags&(ALLOWTABLE|FORBIDTABLE)) {
  937.         if (ALLOWED)
  938.             return(NORMAL);
  939.         else
  940.             return(IGNORE);
  941.     }
  942.     if (flags&ALPHA)
  943.         if (InTable(c,AlphaTable))
  944.             return(NORMAL);
  945.     if (flags&GERMAN)
  946.         if (InTable(c,GermanTable))
  947.             return(NORMAL);
  948.     if (flags&NUM)
  949.         if (InTable(c,NumTable))
  950.             return(NORMAL);
  951.     if (flags&OTHER)
  952.         if (InTable(c,OtherTable))
  953.             return(NORMAL);
  954.     if (flags&SPACES)
  955.         if ((c=='\t')||(c==' '))
  956.             return(SPACE);
  957.     return(IGNORE);
  958. }
  959.  
  960. /**********************************************************************\
  961.  *                              InTable                               *
  962.  *                                                                    *
  963.  *        Check whether a char is found in the table supplied         *
  964. \**********************************************************************/
  965.  
  966. BOOL InTable(char c,char *tb)
  967. {
  968.     if ((*tb=='\t')&&(tb[1]=='R')) {    /* Hey, somebody's using a RangeTable! */
  969.         tb+=2;
  970.         while (*tb) {
  971.             if ((c>=*tb)&&(c<=tb[1]))
  972.                 return(TRUE);
  973.             tb+=2;
  974.         }
  975.     }
  976.     else {
  977.         while (*tb) {
  978.             if (*tb==c) return(TRUE);
  979.             tb++;
  980.         }
  981.     }
  982. }
  983.  
  984. /**********************************************************************\
  985.  *                              EmptyBuf                              *
  986.  *                                                                    *
  987.  *                     Clean up the serial buffer                     *
  988. \**********************************************************************/
  989.  
  990. void EmptyBuf()
  991. {
  992. ULONG len;
  993. char buf[128];
  994.     if (sld) {
  995.         len=SerBuffer(sld);
  996.         while (len) {
  997.             ReadSer(sld,buf,126);
  998.             len=SerBuffer(sld);
  999.         }
  1000.     }
  1001. }
  1002.  
  1003. VOID SendString(char *txt)
  1004. {
  1005.     if (!con)
  1006.         WriteSer(sld,txt,strlen(txt));
  1007. }
  1008.  
  1009. /**********************************************************************\
  1010.  *                              ScanData                              *
  1011.  *                                                                    *
  1012.  *                 Find out some stuff about the user                 *
  1013. \**********************************************************************/
  1014.  
  1015. VOID ScanData()
  1016. {
  1017. FILE    *f;
  1018. BPTR     fh;
  1019. char str[256];
  1020. long pos;
  1021. BOOL _OK;
  1022.     if (f=fopen("ram:userParam","r")) {
  1023.         getstring(BBSBaud,31,f);
  1024.         getstring(BBSUser,79,f);
  1025.         getstring(BBSStatus,31,f);
  1026.         getstring(BBSOnline,31,f);
  1027.         getstring(BBSRest,31,f);
  1028.         getstring(BBSDev,31,f);
  1029.         getstring(BBSTerm,31,f);
  1030.         fclose(f);
  1031.         baud=atol(BBSBaud);
  1032.         con=atoi(BBSDev);
  1033.         strupr(BBSTerm);
  1034.         if (strnicmp(BBSTerm,"TTY",3))
  1035.             Ansi=TRUE;
  1036.         else
  1037.             Ansi=FALSE;
  1038.         if (baud<300) return;
  1039.     }
  1040.     else
  1041.         strcpy(BBSBaud,"Unknown");
  1042.     _OK=FALSE;
  1043.     if (fh=Open("ram:em-param",MODE_OLDFILE)) {
  1044.         if (Read(fh,str,128L)>4) {
  1045.             ep2=(struct Prefer *)atol(str);
  1046.             _OK=TRUE;
  1047.         }
  1048.         if (fh) Close(fh);
  1049.     }
  1050.     if (!_OK) {
  1051.         if (fh=Open("s:euro.defslc",MODE_OLDFILE)) {
  1052.             if (Read(fh,&ep,sizeof(struct Prefer))) {
  1053.                 ep2=&ep;
  1054.                 _OK=TRUE;
  1055.             }
  1056.             Close(fh);
  1057.         }
  1058.     }
  1059.     if (_OK) {
  1060.         SERUNIT=ep2->serdat.Unit;
  1061.         strcpy(SERDEVNAME,ep2->serdat.SerName);
  1062.         strcat(SERDEVNAME,".device");
  1063.         strcpy(str,ep2->userpath);
  1064.         strcat(str,"userdatei");
  1065.         strcpy(protokoll,ep2->protokollpath);
  1066.         strcpy(newusf,ep2->persoenlichpath);
  1067.         BBS_FLAGS=SERF_RAD_BOOGIE;
  1068.         if (!(ep2->serdat.Xon&1))
  1069.             BBS_FLAGS|=SERF_XDISABLED;
  1070.         if (ep2->serdat.Xon&2)
  1071.             BBS_FLAGS|=SERF_7WIRE;
  1072.         strcat(newusf,BBSUser);
  1073.         strcat(newusf,"/Antrag");
  1074.         if (fh=Open(str,MODE_OLDFILE)) {
  1075.             Seek(fh,0L,OFFSET_END);
  1076.             usersize=pos=Seek(fh,0L,OFFSET_BEGINNING);
  1077.             if (user=(struct Usereintrag *)AllocMem(pos,MEMF_CLEAR)) {
  1078.                 Read(fh,user,pos);
  1079.                 numuser=pos/sizeof(struct Usereintrag);
  1080.             }
  1081.             else {
  1082.                 numuser=0;
  1083.                 ToProto("\nNicht genug Speicher für Userstruktur! ");
  1084.             }
  1085.             Close(fh);
  1086.         }
  1087.         else
  1088.             ToProto("\nUserdatei nicht zu öffnen! ");
  1089.     }
  1090. }
  1091.  
  1092. VOID OpenStuff()
  1093. {
  1094. BPTR op;
  1095.     if (!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0L)))
  1096.         ex();
  1097.     if (!(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0L)))
  1098.         ex();
  1099.     if (!(SerLibBase=(struct SerLibBase *)OpenLibrary("serlib.library",2L))) {
  1100.         printf("Konnte SerLib.Library nicht öffnen!\n");
  1101.         ex();
  1102.     }
  1103.     if (!(tr=OpenTimer())) ex();
  1104.     if (!(scr=OpenScreen(&scrdef))) {
  1105.         puts("Konnte Screen nicht öffnen!\n");
  1106.         ex();
  1107.     }
  1108.     windef.Screen=scr;
  1109.     if (!(win=OpenWindow(&windef))) {
  1110.         puts("Konnte Fenster nicht öffnen!\n");
  1111.         ex();
  1112.     }
  1113.     vp=&(scr->ViewPort);
  1114.     rp=&(scr->RastPort);
  1115.     LoadRGB4(vp,Palette,4L);
  1116.     SetDrMd(rp,JAM2);
  1117.     SetAPen(rp,1L);
  1118. }
  1119.  
  1120. VOID ex()
  1121. {
  1122. FILE *f;
  1123.     if (user) FreeMem(user,usersize);
  1124.     if (tr) CloseTimer(tr);
  1125.     if (win) CloseWindow(win);
  1126.     if (scr) CloseScreen(scr);
  1127.     if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
  1128.     if (GfxBase) CloseLibrary((struct Library *)GfxBase);
  1129.     if (sld) CloseSerial(sld);
  1130.     if (SerLibBase) CloseLibrary((struct Library *)SerLibBase);
  1131.  
  1132.     if (strlen(newusf)) {
  1133.         if (f=fopen(newusf,"w")) {
  1134.             fprintf(f,"Abgebrochen");
  1135.             fclose(f);
  1136.         }
  1137.     }
  1138.     exit(0);
  1139. }
  1140.  
  1141. VOID getstring(a,l,f)
  1142. char *a;
  1143. int l;
  1144. FILE *f;
  1145. {
  1146.     fgets(a,l,f);    /* das 'a,l,f' ist Zufall, wirklich! */ 
  1147.     a[strlen(a)-1]='\0';
  1148. }
  1149.  
  1150. VOID PositionText(x,y,txt)
  1151. int x,y;
  1152. char *txt;
  1153. {
  1154. char temp[128];
  1155.     if (!con) {
  1156.         SendString(ESC);
  1157.         sprintf(temp,"%d;%dH%s",y+1,x+1,txt);
  1158.         SendString(temp);
  1159.     }
  1160.     DisplayString(x,y,txt);
  1161. }
  1162.  
  1163. void PositionChar(int x,int y, char c)
  1164. {
  1165. char temp[16];
  1166.     if (!con) {
  1167.         SendString(ESC);
  1168.         sprintf(temp,"%d;%dH%c",y+1,x+1,c);
  1169.         SendString(temp);
  1170.     }
  1171.     DisplayChar(x,y,c);
  1172. }
  1173.  
  1174. struct timerequest *OpenTimer()
  1175. {
  1176. struct timerequest *tr;
  1177.     if (!(tport=CreatePort(0,0))) {
  1178.         printf("Konnte einen Port nicht erzeugen...\n");
  1179.         return(0L);
  1180.     }
  1181.     if (!(tr=(struct timerequest *)CreateExtIO(tport,(long)sizeof(struct timerequest)))) {
  1182.         printf("Probs bei CreateExtIO\n");
  1183.         return(0L);
  1184.     }
  1185.     if (OpenDevice(TIMERNAME,(ULONG)UNIT_VBLANK,(struct IORequest *)tr,0L)) {
  1186.         printf("Opendevice für Timer fehlgeschlagen...\n");
  1187.         DeleteExtIO((struct IORequest *)tr);
  1188.         tr=NULL;
  1189.         return(0L);
  1190.     }
  1191.     return(tr);
  1192. }
  1193.  
  1194. void CloseTimer(struct timerequest *tr)
  1195. {
  1196.     CloseDevice((struct IORequest *)tr);
  1197.     DeleteExtIO((struct IORequest *)tr);
  1198. }
  1199.  
  1200. void DoTime(struct timerequest *tr, ULONG secs)
  1201. {
  1202.     tv.tv_secs=secs/10;
  1203.     tv.tv_micro=100000*(secs-tv.tv_secs*10);
  1204.     tr->tr_time=tv;
  1205.     tr->tr_node.io_Command=TR_ADDREQUEST;
  1206.     SendIO((struct IORequest *)tr);
  1207. }
  1208.  
  1209. void DisplayString(int x, int y, char *txt)
  1210. {
  1211. int l;
  1212.     Move(rp,(x<<3),((y<<3)+7));
  1213.     l=strlen(txt);
  1214.     if ((l+x)>=78) {
  1215.         Text(rp,txt,78-x);
  1216.         y++;
  1217.         Move(rp,0,(y+1)<<8+7);
  1218.         Text(rp,&txt[78-x],l+x-78);
  1219.         x+=l-78;
  1220.     }
  1221.     else {
  1222.         Text(rp,txt,l);
  1223.         x+=l;
  1224.     }
  1225. }
  1226.  
  1227. void DisplayChar(int x, int y, char c)
  1228. {
  1229.     Move(rp,(x<<3),((y<<3)+7));
  1230.     Text(rp,&c,1L);
  1231. }
  1232.  
  1233. void ToProto(char *str)
  1234. {
  1235. FILE *f;
  1236. long t;
  1237.     if (f=fopen(protokoll,"a")) {
  1238.         fputs(str,f);
  1239.         time(&t);
  1240.         fputs(ctime(&t),f);
  1241.         fclose(f);
  1242.     }
  1243. }
  1244.  
  1245.  
  1246.