home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 5 / QRZ Ham Radio Callsign Database - Volume 5.iso / files / amiga / csrc720j.lzh / funcs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-23  |  10.9 KB  |  478 lines

  1. /* funcs.c */
  2.  
  3. /* Some replacement routines for the amiga */
  4. #include <stdio.h>
  5. #include <time.h>
  6. /* for Execute call at the end */
  7. #include <libraries/dos.h>
  8. #include "mb.h"
  9. extern short debug;
  10. extern char l_date[7], l_time[5],tmpstr[];
  11. extern char optflags[];
  12. extern char passchr, vhfstream,hfstream;
  13. extern char *inittnc();
  14. #define true 1
  15. #define false 0
  16.  
  17. extern char hostport;
  18. /*
  19.  * Get the audio device for the beep and force some commands at
  20.  * the TNC
  21.  */
  22.  
  23. ioinit()
  24. {
  25.    register char *p;
  26.    char tnc_on[12];
  27.  
  28.    if(hostport == 'A')strcpy(&tnc_on[0],"tnc.on");
  29.    else               sprintf(&tnc_on[0],"tnc.on.%c",hostport);
  30.    initbeep();
  31.    if(p = inittnc(&tnc_on[0],1))ttputs(p);
  32. }
  33.  
  34. /* This is supposed to turn off interrupts but since it is the last
  35.    thing called by done() in mb.c I use it to do any cleanup for the
  36.    amiga
  37. */
  38. iooff()
  39. {
  40.    register char *p;
  41.    char tnc_off[12];
  42.  
  43.    if(hostport == 'A')strcpy(&tnc_off[0],"tnc.off");
  44.    else               sprintf(&tnc_off[0],"tnc.off.%c",hostport);
  45.    if(p = inittnc(&tnc_off[0],1))printf(p);
  46.    donebeep();
  47. }
  48.  
  49.  
  50. /*
  51.  *  Fill the globals "l_date", "l_time", and "dt" with
  52.  *  the current date and time by reading the system clock.
  53.  *  l_time is HHMM, l_date is YYMMDD.
  54.  *  dt has the format of a directory item date/time.
  55.  */
  56. extern short timezone;
  57. int cursecs;
  58. curtim()
  59. {
  60.    struct tm *ct;
  61.    time_t ltime;
  62.  
  63.    time(<ime);
  64.    ct = localtime(<ime);
  65.    cursecs = ct->tm_sec;
  66.  
  67.    sprintf(l_time, "%02d%02d", ct->tm_hour, ct->tm_min);
  68.    sprintf(l_date, "%02d%02d%02d", ct->tm_year, ct->tm_mon + 1, ct->tm_mday);
  69.    /* month returned by localtime is 0-11 */
  70.  
  71.    /* Change the local time into UTC and generate date/time string for
  72.       initmsg and cremsg which store the date/time in UTC.
  73.       Adjust for daylight savings - dst() returns the number of minutes of
  74.       time required to adjust local time to UTC.
  75.    */
  76.    ltime += dst(timezone)*60L;
  77.    ct = localtime(<ime);
  78.    sprintf(z_time, "%02d%02d", ct->tm_hour, ct->tm_min);
  79.    sprintf(z_date, "%02d%02d%02d", ct->tm_year, ct->tm_mon + 1, ct->tm_mday);
  80. }
  81. long gettime()
  82. {
  83.    long cur[3],now;
  84.    DateStamp((struct DateStamp *)&cur[0]);
  85.    now = cur[0]*24*60*60;
  86.    now += cur[1]*60;
  87.    now += cur[2]/50;
  88.    return(now);
  89. }
  90. /*
  91.  *  Check a timer.
  92.  */
  93.  
  94. chktmr(l)
  95. long l;
  96. {
  97.    extern long gettime();
  98.    long cur[3];
  99.  
  100.    if (gettime() > l) return (false);
  101.    return (true);
  102. }
  103.  
  104. /*
  105.  *  Set a timer.
  106.  */
  107.  
  108. settmr(l, i)
  109. long *l;
  110. int i;
  111. {
  112.    extern  long gettime();
  113.    *l = gettime() + (long)i;
  114. }
  115.  
  116. char port_flag,cmnd_flag;
  117. putp_flag(c)
  118. char c;
  119. {
  120.    port_flag = c;
  121. }
  122. getp_flag()
  123. {
  124.    return(port_flag);
  125. }
  126. putc_flag(c)
  127. char c;
  128. {
  129.    cmnd_flag = c;
  130. }
  131. getc_flag()
  132. {
  133.    return(cmnd_flag);
  134. }
  135. #ifdef NEWPASS
  136. int numpass,pwdint[MAXPASS];
  137. pass()
  138. {
  139.    char tmpnum[MAXPASS];
  140.  
  141.    register char *p;
  142.    register int i,j;
  143.    int sum;
  144.    /* don't do the thing at all if there's no integers to use
  145.       or there was an error in reading the list in mbinit
  146.    */
  147.    if(numpass == 0)return false;
  148.    sum = 0;
  149.    /* clear tmpnum array
  150.       It is used to ensure that four distinct integers are
  151.       produced.
  152.    */
  153.    for(p = &tmpnum[0];p<&tmpnum[MAXPASS];p++)*p = 0;
  154.    /* get four distinct random integers to generate the password */
  155.    for(i = 0;i < 4;i++) {
  156.       do {
  157.          j = ((rand() & 0x7fff) >> 4) % numpass;
  158.          /* make sure rand produces four distinct numbers otherwise
  159.             it weakens the password scheme
  160.          */
  161.          if(tmpnum[j])continue;
  162.          tmpnum[j] = 1;
  163.          sum += pwdint[j];
  164.          sprintf(tmpstr, " %2d", j+1);
  165.          outstr(tmpstr);
  166.          break;
  167.       }while(1);
  168.    }
  169.    outstr("\n");
  170.    getdat();
  171.    if(atoi(port->line) == sum)return true;
  172.    return false;
  173. }
  174. /*
  175.    New and more secure password function called from mbinit to set up
  176.    the password array.
  177. */
  178. initpwd()
  179. {
  180.    register int i,j;
  181.    register char *p;
  182.    char *rdstr();
  183.    p = rdstr();
  184.    while(*p == ' ')p++;
  185.    for(i=0;i<MAXPASS;i++) {
  186.       if((pwdint[i] = atoi(p)) <= 0) {
  187.          return(0);
  188.       }
  189.       while(*p && (*p >= '0') && (*p <= '9'))p++;
  190.       if((*p == 0) || (*p == '\n') || (*p == '\r')){
  191.          if(i+1 < MINPASS)return;
  192.          return(i+1);
  193.       }
  194.       while(*p == ' ')p++;
  195.       /* a backslash at the end of a line indicates more integers
  196.          on the next line.
  197.       */
  198.       if(*p == '\\') {
  199.          p = rdstr();
  200.          while(*p == ' ')p++;
  201.          continue;
  202.       }
  203.    }
  204.    return(i+1);
  205. }
  206. #endif
  207. donefunc()
  208. {
  209.    done(0);
  210. }
  211. titles()
  212. {
  213.    window_title(mfhs->next_msg-1,mfhs->count);
  214. }
  215. funlink(file)
  216. UBYTE  *file;
  217. {
  218.    return(DeleteFile(file));
  219. }
  220. replace_bbs()
  221. {
  222.    int user_num;
  223.    USER ubuf;
  224.    /* the extra tests here try to avoid the expense of the disk I/O
  225.       required if we must look in the user file
  226.    */
  227.    if(!optflags[1])return(1);
  228.    if(!iscall(port->mmhs->to))return(2);
  229.    if((user_num = finduser(port->mmhs->to)) == 0)return(3);
  230.    read_rec(ufl,user_num,&ubuf);
  231.    /* Is there a call in the home_bbs ? */
  232.    if(ubuf.home_bbs[0] == ' ')return(4);
  233.    strncpy(port->mmhs->bbs,&ubuf.home_bbs[0],ln_call);
  234.    /* This new call may have a hierarchical address */
  235.    chkhier();
  236.    return(0);
  237. }
  238. do_system(cmd)
  239. UBYTE *cmd;
  240. {
  241.    /* Using Open("*",...) to get a handle on the window does not work.
  242.       It gives a handle to the CLI that started up CBBS ... NOT the
  243.       window that CBBS is in ... so the output goes to the wrong window
  244.       anyway
  245.    */
  246.    long Execute(),Open();
  247.    if(Execute(cmd,0L,0L)) {
  248.       return(0);
  249.    }
  250.    return(1);
  251. }
  252.  
  253. /* Clean up a string before it is sent to the TNC or to the screen
  254. */
  255.  
  256. str_search(str)
  257. unsigned char *str;
  258. {
  259.    register unsigned char *cp,*tp;
  260.    short in_out;
  261.  
  262.    /* Is this going to the console or to TNC? */
  263.    in_out = (port->dev != p_console);
  264.    cp = str;
  265.    tp = (unsigned char *) &tmpstr[0];
  266.    while(*cp) {
  267.       /* insert the pass character for stream characters */
  268.       if(in_out && passchr) {
  269.          if((*cp == (unsigned char) vhfstream) ||
  270.             (*cp == (unsigned char) hfstream)) {
  271.             *tp++ = passchr;
  272.             *tp++ = *cp++;
  273.             continue;
  274.          }
  275.       }
  276.       if((*cp >= ' ') && (*cp <= 0176)) {
  277.          *tp++ = *cp++;
  278.          continue;
  279.       }
  280.       /* Allow BEL HT CR and ^Z through. All others are omitted
  281.       */
  282.       switch(*cp) {
  283.       case  7:    /* BEL */
  284.       case 26:    /* Control -Z */
  285.          if(!in_out)break;
  286.       case  9:    /* TAB */
  287.       case 13:    /* CR */
  288.       case 10:    /* LF */
  289.          *tp++ = *cp;
  290.          break;
  291.       }
  292.       cp++;
  293.    }
  294.    *tp = 0;
  295.    outstr(tmpstr);
  296. }
  297.  
  298. /* Replacement command parser. This fixes up the problem with THEBOX
  299.    which sends a command of the form:
  300.    sb amsat @dl <df3ix $bid #7
  301.    where CBBS expects to see
  302.    sb amsat @ dl < df3ix $bid #7
  303. */
  304. parse()
  305. {
  306.    register char *in, *out;
  307.    register short i;
  308.    for(i = 0; i < maxflds;i++) {
  309.       port->fld[i] = nullstr;
  310.    }
  311.    in  = port->line;
  312.    out = port->cmd;
  313.    port->flds = 0;
  314.  
  315.    while(*in && (port->flds < maxflds) && (out < (port->cmd + cmdlen - 1))) {
  316.       /* Process each string
  317.          Start by removing leading blanks, tabs etc.
  318.          Note that when this gets to the end of the line this will
  319.          skip by the linefeed too
  320.       */
  321.       while(*in && (*in <= ' '))in++;
  322.       if(*in == 0)break;
  323.       port->fld[port->flds++] = out;
  324.       /* Now process the field itself.
  325.          If it begins with one of the special characters @ or < then 
  326.          treat this as though it has a space after it, even if it
  327.          doesn't.
  328.          If it begins with " then look for the trailing " and store it
  329.          all as one string. This fix allows a tweak to the 'L' command.
  330.       */
  331.       switch(*in) {
  332.       case '@':
  333.       case '<':
  334.          *out++ = *in++;
  335.          break;
  336.       case '"':
  337.          /*
  338.             Allow a quoted string as an argument.
  339.             The quotes are stored in the output argument string.
  340.             If the trailing quote is missing then just store a
  341.             null and don't try to copy the linefeed
  342.          */
  343.          *out++ = *in++;
  344.          while(*in && (*in != '"') && (*in != '\n')
  345.                    && (out < (port->cmd + cmdlen - 1)))
  346.             *out++ = toupper(*in++);
  347.          if(*in == '"')
  348.             *out++ = *in++;
  349.          break;
  350.       default:
  351.          while(*in && (*in > ' ') && (out < (port->cmd + cmdlen - 1))) {
  352.             /*
  353.                If the user types ve5va@n8gtc then split it up.
  354.             */
  355.             if((port->flds == 2) && (*in == '@'))break;
  356.             *out++ = toupper(*in++);
  357.          }
  358.          break;
  359.       }
  360.       *out++ = 0;
  361.    }
  362.    *out = '\0';
  363.  
  364.    port->opt1 = *port->fld[0];
  365.    port->opt2 = *(port->fld[0] + 1);
  366.    if(!port->opt2)
  367.       port->opt2 = ' ';
  368. }
  369.  
  370. /* Send Reply command */
  371. int srcmd_flag = 0;
  372. srpmsg()
  373. {
  374. /* Until this command works properly send out a 'Sorry' message */
  375. outstr("Sorry - this command has been removed until it works properly\n");
  376. srcmd_flag = 0;
  377. last_msg.type = 0;
  378. return;
  379. /* Comment out this code until it works properly.
  380.    if((last_msg.type == 0) || (port->flds != 1)) {
  381.       port->msg = mwhat;
  382.       return;
  383.    }
  384.  
  385.    sprintf(port->line,"SP %s %s%s",last_msg.from,(last_msg.bbs[0] ? "@":""),
  386.                   last_msg.bbs);
  387.    outstr(port->line);
  388.    outstr("\n");
  389.    srcmd_flag = 1;
  390.    parse();
  391.    sndmsg();
  392.    last_msg.type = 0;
  393.    srcmd_flag = 0;
  394. */
  395. }
  396. /* This next routine must not use tmpstr */
  397. prt_subj()
  398. {
  399.    if(toupper(last_msg.title[0]) != 'R' ||
  400.       toupper(last_msg.title[1]) != 'E' ||
  401.       last_msg.title[2] != ':') {
  402.       /* Prefix the title with "Re:" if there isn't already one there */
  403.       strncpy(port->mmhs->title,"Re: ",4);
  404.       strncpy(&port->mmhs->title[4],last_msg.title,mhtitl-4);
  405.    }
  406.    else strncpy(port->mmhs->title,last_msg.title,mhtitl);
  407.    outstr("Subject: \n");
  408.    outstr(port->mmhs->title);
  409.    outstr("\n");
  410. }
  411.  
  412. /* Create file names based on the port name */
  413. portfile()
  414. {
  415.    if(hostport == 'A')return;
  416.    fchange(hrdfile);
  417.    fchange(monfile);
  418.    fchange(lgfile);
  419. /*   fchange(fwdfile);  */
  420. }
  421. fchange(s)
  422. char *s;
  423. {
  424.    register char *p;
  425.    p = s;
  426.    /* Find the null character at the end of the string */
  427.    while(*p)p++;
  428.  
  429.    /* There's nothing in the string!! */
  430.    if(p == s)return;
  431.  
  432.    /* Then backup until we find a period */
  433.    while((p!=s) && (*p != '.'))p--;
  434.    /* If there's no period, then add one */
  435.    if(*p != '.') {
  436.       while(*p)p++;
  437.       *p = '.';
  438.    }
  439.    p++;
  440.    *p++ = hostport;
  441.    *p = 0;
  442. }
  443.  
  444. test_bbs()
  445. {
  446.    FILE *fpi;
  447.    char tmp_call[8];
  448.  
  449.    /* Check for unknown @BBS field - make sure tmpstr is non-null to start*/
  450.  
  451.    strcpy(tmpstr,msgdir);
  452.    if((port->mmhs->bbs[0] != ' ') && !iscall(port->mmhs->bbs)) {
  453.       unbl(tmp_call,port->mmhs->bbs,ln_call);
  454.       strcat(tmpstr,tmp_call);
  455.       strcat(tmpstr,".dis");
  456.       if((fpi = fopen(tmpstr,"r")) == NULL) {
  457.          unbl(tmpstr,port->mmhs->bbs,ln_call);
  458.          return(1);
  459.       }
  460.       fclose(fpi);
  461.    }
  462.    return(0);
  463. }
  464.  
  465. opchange()
  466. {
  467.    register char c;
  468.  
  469.    c = toupper(*port->fld[1]);
  470.    if((c < 'A') || (c > 'J')) {
  471.       port->msg = mwhat;
  472.       return;
  473.    }
  474.    optflags[c-'A'] ^= 1;
  475.    sprintf(tmpstr,"Option %c now %s\n",c,optflags[c-'A']?"ON":"OFF");
  476.    ttputs(tmpstr);
  477. }
  478.