示例#1
0
   void process_directive(std::string expression)
   {
      expression = trim_whitespace(expression);

      if ('$' != expression[0])
         return;
      else if ("$enable_cache" == expression)
         persist_symbol_table() = true;
      else if ("$disable_cache" == expression)
         persist_symbol_table() = false;
      else if ("$enable_symbol_dump" == expression)
         symbol_dump() = true;
      else if ("$disable_symbol_dump" == expression)
         symbol_dump() = false;
      else if ("$enable_assignment_dump" == expression)
         assignment_dump() = true;
      else if ("$disable_assignment_dump" == expression)
         assignment_dump() = false;
      else if ("$enable_timer" == expression)
         display_total_time() = true;
      else if ("$enable_compile_timer" == expression)
         display_total_compile_time() = true;
      else if ("$disable_timer" == expression)
         display_total_time() = false;
      else if ("$disable_compile_timer" == expression)
         display_total_compile_time() = false;
      else if ("$enable_usr" == expression)
         enable_usr() = true;
      else if ("$disable_usr" == expression)
         enable_usr() = false;
      else if ("$enable_local_vardef" == expression)
         disable_local_vardef() = false;
      else if ("$disable_local_vardef" == expression)
         disable_local_vardef() = true;
      else if ("$list_vars" == expression)
         list_symbols();
      else if ("$clear_functions" == expression)
         clear_functions();
      else if ((0 == expression.find("$load ")) && (expression.size() > 7))
         process_from_file(expression.substr(6,expression.size() - 6));
      else if ((0 == expression.find("$disable arithmetic ")) && (expression.size() >= 21))
         process_disable_arithmetic(expression.substr(20,expression.size() - 20));
      else if ((0 == expression.find("$disable assignment ")) && (expression.size() >= 21))
         process_disable_assignment(expression.substr(20,expression.size() - 20));
      else if ((0 == expression.find("$disable inequality ")) && (expression.size() >= 21))
         process_disable_inequality(expression.substr(20,expression.size() - 20));
      else if ((0 == expression.find("$enable arithmetic ")) && (expression.size() >= 20))
         process_enable_arithmetic(expression.substr(19,expression.size() - 19));
      else if ((0 == expression.find("$enable assignment ")) && (expression.size() >= 20))
         process_enable_assignment(expression.substr(19,expression.size() - 19));
      else if ((0 == expression.find("$enable inequality ")) && (expression.size() >= 20))
         process_enable_inequality(expression.substr(19,expression.size() - 19));
      else if ("$begin" == expression)
         process_multiline();
      else if (0 == expression.find("$function"))
         process_function_definition(expression);
      else
         printf("\nERROR - Invalid directive: %s\n",expression.c_str());
   }
示例#2
0
文件: SNTP.C 项目: Strongc/DC_source
/* ********************************************************************   */
int sntp_process_result(int socket_no, PNTP_TIME_FORMAT current_timestamp,
                        int version, dword ticks_when_sent,
                        PEBSTIME res_ebs_tod)

{
int             n_received;
NTP_PKT         ntp_response;
NTP_TIME_FORMAT temp_time1;
NTP_TIME_FORMAT temp_time2;
NTP_TIME_FORMAT t1;
NTP_TIME_FORMAT t2;
NTP_TIME_FORMAT t3;
NTP_TIME_FORMAT t4;
NTP_TIME_FORMAT local_offset;
NTP_TIME_FORMAT delay_time;         /* round trip delay */
#if (DELAY_TICKS)
dword           delay_ticks;
dword           curr_ticks;
#endif
RTIP_BOOLEAN    gmt_neg;

#if (DELAY_TICKS)
    curr_ticks = ks_get_ticks();
    if (CHECK_GREATER(curr_ticks, ticks_when_sent))
        delay_ticks = curr_ticks - ticks_when_sent;
    else
        delay_ticks = (int)( (long)((long)curr_ticks - 
                             (long)ticks_when_sent) );

#if (DEBUG_DELAY_TICKS)
    DEBUG_ERROR("ks_get_ticks, ticks_when_sent: ", DINT2,
        curr_ticks, ticks_when_sent);
#endif
#endif

    /* Get a packet   */
    n_received = recv(socket_no, (PFCHAR)&ntp_response, 
                      sizeof(ntp_response), 0);
    if (n_received < 0)
    {
        DEBUG_ERROR("sntp_process_result: recv failed", EBS_INT1, 
            xn_getlasterror(), 0);
    }

    closesocket(socket_no);

    /* verify response - mode   */
    if ( ((ntp_response.li_vn_mode & NTP_MODE_MASK) != NTP_SYM_PASSIVE) &&
         ((ntp_response.li_vn_mode & NTP_MODE_MASK) != NTP_RESPONSE) )
    {
        DEBUG_ERROR("sntp_process_result: response invalid: exp, act", 
            EBS_INT2, 
            NTP_SYM_PASSIVE, ntp_response.li_vn_mode & NTP_MODE_MASK);
        return(-1);
    }

    /* verify response - stratum   */
    if ( (ntp_response.stratum < 1) || (ntp_response.stratum > 14) )
    {
        DEBUG_ERROR("sntp_process_result: stratum invalid: ", EBS_INT1,
            ntp_response.stratum, 0);
        return(-1);
    }

    /* verify response - version   */
    if ( (ntp_response.li_vn_mode & NTP_VERSION_MASK) != version )
    {
        DEBUG_ERROR("sntp_process_result: response invalid - version : exp, act", 
            EBS_INT2, version, 
            ntp_response.li_vn_mode & NTP_VERSION_MASK);
        return(-1);
    }

    ntp_response.rcv_timestamp.seconds = 
        net2hl(ntp_response.rcv_timestamp.seconds);

    ntp_response.ref_timestamp.seconds = 
        net2hl(ntp_response.ref_timestamp.seconds);

    ntp_response.transmit_timestamp.seconds = 
        net2hl(ntp_response.transmit_timestamp.seconds);

    /* seconds since Jan 1, 1970                  */
/*  DEBUG_ERROR("TIME SECONDS: seconds: ", DINT2, */
/*      ntp_response.rcv_timestamp.seconds,       */
/*      ntp_response.rcv_timestamp.frac_sec);     */

#if (DISPLAY_RCV_TIME)
    DEBUG_ERROR("\n***** RCV TIME *****", NOVAR, 0, 0);
    display_sntp_time(ntp_response.rcv_timestamp.seconds);
#endif

#if (DISPLAY_INT_TIMES)
/*  DEBUG_ERROR("***** REF TIME *****", NOVAR, 0, 0);      */
/*  display_sntp_time(ntp_response.ref_timestamp.seconds); */


/*  DEBUG_ERROR("***** TRANSMIT TIME *****", NOVAR, 0, 0);      */
/*  display_sntp_time(ntp_response.transmit_timestamp.seconds); */
#endif

#if (DELAY_TICKS)
    t4.seconds = delay_ticks / ks_ticks_p_sec();
    t4.frac_sec = 0;    /* tbd */
    DEBUG_ERROR("delay_ticks, t4.sec", DINT2, delay_ticks, t4.seconds);
#endif

    /* set the following                    */
    /* t2 = time request received by server */
    /* t3 = time reply sent by server       */
    /* t4 = time reply received by client   */
    STRUCT_COPY(t1, *current_timestamp); 
    STRUCT_COPY(t2, ntp_response.rcv_timestamp);
    STRUCT_COPY(t3, ntp_response.transmit_timestamp);
#if (!DELAY_TICKS)
    STRUCT_COPY(t4, *current_timestamp);
#endif

    /* set time response took to arrive from time sent   */
    /* delay_time = (t4-t1) - (t2-t3)                    */
    time_sub(&temp_time1, &t4, &t1);
    time_sub(&temp_time2, &t2, &t3);
    time_sub(&delay_time, &temp_time1, &temp_time2);

    /* calculate local time offset   */
    /* local clock offset            */
    time_sub(&temp_time1, &t2, &t1);
    time_sub(&temp_time2, &t3, &t4);
    time_add(&local_offset, &temp_time1, &temp_time2);
    time_div_2(&local_offset);

#if (DISPLAY_DELAY_OFFSET)
    display_total_time("\nDELAY TIME: ", delay_time.seconds);
    display_total_time("OFFSET TIME: ",  local_offset.seconds);
#endif

    gmt_neg = FALSE;
#if (!ADD_OFFSET)
    if (CFG_GMT_DIFF < 0)
    {
        gmt_neg = TRUE;
        /* convert hours to seconds, hence multiply by 3600;   */
        /* make it positive and it will be subtracted below    */
        local_offset.seconds = -(CFG_GMT_DIFF * SEC_PER_HOUR);
    }
    else
    {
        /* CFG_GMT_DIFF is positive so seconds is always positive   */
        local_offset.seconds = (dword)(CFG_GMT_DIFF * SEC_PER_HOUR);
    }
#endif
    local_offset.frac_sec = 0;

    /* update time with delay   */
    time_add(&temp_time1, &t3, &delay_time);

    /* save current time for next request   */
    STRUCT_COPY(*current_timestamp, temp_time1); 

    /* update time with time zone   */
    if (gmt_neg)
        time_sub(&temp_time2, &temp_time1, &local_offset);
    else
        time_add(&temp_time2, &temp_time1, &local_offset);


/*  display_total_time("BEFORE CONVERSION TO ebs_tod ", temp_time2.seconds);   */
/*  display_total_time("FINAL TIME ", temp_time2.seconds);                     */

    /* convert time returned by SNTP server to RTIP internal format   */
    convert_time_to_ebs_time(temp_time2.seconds, res_ebs_tod);

    return(0);
}