⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stattab.cpp

📁 基于单片机的 snmp协议解析的一些原代码 给有用的 同行
💻 CPP
字号:
//  Copyright (c) 1996  Federal Highway Administration
//
//  This software has been developed for the Federal Highway Administration
//  by Viggen Corporation under contract with Oak Ridge National Lab.
//
//  Permission to use, copy, and distribute this software for any purpose
//  without fee is hereby granted, provided that the above copyright notice
//  appears in all copies and that both the copyright and this permission notice
//  appear in the supporting documentation.
//
//  Permission to modify this software is granted provided that the above
//  copyright and this permission notice appears in the modified software.
//
//  This software is provided "as is" with no warranty expressed or implied.
//
//  For additional information, please go to the Web site www.ntcip.org.
//
/*******************************************************************************
 *
 * Copyright (c) 1997 Viggen Corporation
 *
 * Permission to use, copy, and distribute this software for any purpose
 * without fee is hereby granted, provided that this copyright notice
 * appears in all copies and this permission notice appears in the
 * supporting documentation.
 *
 * Permission to modify this software is granted provided that the above
 * copyright and this permission notice appears in the modified software.
 *
 ******************************************************************************/


 /*********************************************
 *
 * stattab.cpp
 *
 * 9/29/97		Glenn Pruitt
 *********************************************/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "lexical.h"
#include "stattab.h"

//Function definitions

void insert_statement_record(struct STTAB **the_table, int index,
		long start, long end, int type, int next, int jump)
{
	struct STTAB *ptr;
   struct STTAB *curr;
   struct STTAB *last;

   //Allocate and fill structure
   ptr = (struct STTAB *)safe_alloc(1,sizeof(struct STTAB));
   ptr->next = NULL;
   ptr->index = index;
   ptr->start = start;
   ptr->end = end;
   ptr->type = type;
   ptr->next_statement = next;
   ptr->jump_statement = jump;

	if(*the_table == NULL)
   {
   	//add to head
      *the_table = ptr;
      return;
   }
   else
   {
   	//insert in correct place (ordered by index)
      curr = *the_table;
      while(curr && (curr->index < ptr->index))
   	{
      	last = curr;
         curr = curr->next;
      }
      if(last == NULL)
      {
      	//Insert to head
         ptr->next = curr;
         *the_table = ptr;
         return;
      }
      if(curr == NULL)
      {
      	//Append to tail
         last->next = ptr;
         return;
      }
      //Insert to middle
      last->next = ptr;
      ptr->next = curr;
      return;
   }
}

void delete_statement_table(struct STTAB **the_table)
{
	struct STTAB *tmp;

   while(*the_table)
   {
   	tmp = *the_table;
      *the_table = (*the_table)->next;
      safe_free(tmp);
   }
   return;
}

char *get_statement_text(struct STTAB *the_table, int index,
								 char *filename, char *buffer)
{
   FILE *fp;
	STTAB *curr;
   char  msg[64];

   curr = the_table;
   while(curr && (curr->index != index))
   	curr = curr->next;
   if(curr)
   {
		fp = fopen(filename,"rt");
      fseek(fp,curr->start,SEEK_SET);

      while(ftell(fp) < curr->end)
      	buffer[strlen(buffer)] = (char)getc(fp);

//      fread(buffer, (size_t)(curr->end - curr->start), 1, fp);

      fclose(fp);
      return(buffer);
   }
   else
   {
   	sprintf(msg,"1Could not find statement index %d.\n",index);
   	error_message(msg);
      return("");
	}
}

int get_next_index(struct STTAB *the_table, int index)
{
	STTAB *curr;
   char msg[64];

   curr = the_table;
   while(curr && (curr->index != index))
   	curr = curr->next;
   if(curr)
		return(curr->next_statement);
   else
   {
   	sprintf(msg,"2Could not find statement index %d.\n",index);
   	error_message(msg);
      return(-1);
   }
}

int set_next_index_to_null(struct STTAB *the_table, int index)
{
	STTAB *curr;
   char msg[64];

   curr = the_table;
   while(curr && (curr->index != index))
   	curr = curr->next;
   if(curr)
   {
   	curr->next_statement = -1;
		return(1);
   }
   else
   {
   	sprintf(msg,"3Could not find statement index %d.\n",index);
   	error_message(msg);
      return(-1);
   }
}

int get_jump_index(struct STTAB *the_table, int index)
{
	STTAB *curr;
   char msg[64];

   curr = the_table;
   while(curr && (curr->index != index))
   	curr = curr->next;
   if(curr)
		return(curr->jump_statement);
   else
   {
   	sprintf(msg,"4Could not find statement index %d.\n",index);
   	error_message(msg);
      return(-1);
   }
}

int get_statement_type(struct STTAB *the_table, int index)
{
	STTAB *curr;
   char msg[64];

   curr = the_table;
   while(curr && (curr->index != index))
   	curr = curr->next;
   if(curr)
		return(curr->type);
   else
   {
   	sprintf(msg,"5Could not find statement index %d.\n",index);
   	error_message(msg);
      return(-1);
   }
}

int count_statements(struct STTAB *the_table)
{
	STTAB *curr;
   int i;

   curr = the_table;
   i = 0;
   while(curr)
   {
   	i++;
      curr = curr->next;
   }
   return(i);
}

int statement_exists(struct STTAB *the_table, int index)
{
	STTAB *curr;

   curr = the_table;
   while(curr)
   {
   	if(curr->index == index)
      	return(1);
      curr = curr->next;
   }
   return(0);
}

long get_start_position(struct STTAB *the_table, int index)
{
	STTAB *curr;
   char msg[64];

   curr = the_table;
   while(curr && (curr->index != index))
   	curr = curr->next;
   if(curr)
		return(curr->start);
   else
   {
   	sprintf(msg,"6Could not find statement index %d.\n",index);
   	error_message(msg);
      return(-1);
   }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -