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

📄 parser.cc

📁 802.15.4 mac 协议源程序
💻 CC
📖 第 1 页 / 共 3 页
字号:
}//---------------------------------------------------------------------////---------------------------------------------------------------------intParseTable::print(FILE * stream) {  TraceSyntax *ts;  Attribute * attribute;  int i = 0;    ts = syntax_list;  while (ts) {    // Output the type    i += fprintf(stream, "%c = %s\n", ts->type, ts->label);    attribute = ts->attributes;    while (attribute) {      i += fprintf(stream, "     -%c <%s> %s\n",attribute->flag, attribute->value_type, attribute->label);       attribute = attribute->next;    }    ts = ts->next;  }  return i;}//---------------------------------------------------------------------////---------------------------------------------------------------------intParseTable::printLatex(FILE * stream) {  TraceSyntax *ts;  Attribute * attribute;  int i = 0;    ts = syntax_list;  while (ts) {    // Output the type    i += fprintf(stream, "  \\begin{tabular}{llll}\n");    if (ts->type == '#') {      i += fprintf(stream, "  \\%c : & %s & & \\\\\n", ts->type, ts->label);    } else {      i += fprintf(stream, "  %c : & %s & & \\\\\n", ts->type, ts->label);    }    // Display attribute flags in a latex table    attribute = ts->attributes;    if (attribute) {      // 3 Columns      while (attribute) {        if (attribute->flag == '#') {          i += fprintf(stream, "    &  -\\%c ", attribute->flag);         } else {          i += fprintf(stream, "    &  -%c ", attribute->flag);         }        i += fprintf(stream, "& <%s> ", attribute->value_type);         i += fprintf(stream, "& %s \\\\\n", attribute->label);         attribute = attribute->next;      }    }    i += fprintf(stream, "  \\end{tabular}\n\n");    ts = ts->next;  }  return i;}//---------------------------------------------------------------------////---------------------------------------------------------------------boolParseTable::parseLine(char * line) {  bool success = true;  char * run = line; // run down the nam event line  TraceSyntax * ts = syntax_list;  Attribute * attribute = NULL;  char attribute_type;  pending->tt = *line;  // Skip over comment lines and empty lines  if (*run == '#' || *run == '\n' || *run == '\r') {    //<zheng: +++>    if (strncmp(run,"# nam4wpan #",12) == 0) {      ParseTable::nam4wpan = true;    }    //</zheng: +++>    return true;  }    // Find Syntax Type  while (ts != NULL) {    if (ts->type == *line) {      break;    }    ts = ts->next;  }  if (ts != NULL) {    // Setup Attribute List to default values    ts->setDefaultAttributeValues();    // Skip over Syntax Type id    run++;    run = eatSpaces(run);        while (*run != '\n') {          //Check for Attribute Flag       if (*run != '-' && ts->type != 'v') {        // Special Case for tcl expression flag        //   The old design has the syntax "v -t <time> <expression>"        while (*run != '-' && *run != '\n' && *run != EOF) {          run++;        }      }      if (*run == '\n' || *run == EOF) {        // Something is seriously wrong with this line in the script        // so bail out with an error        fprintf(stderr, "Unexpected end of line in: %s", line);        fprintf(stderr, "Perhaps you are missing a value following the attribute flag.\n");        if (attribute) {          fprintf(stderr, "Last parsed attribute flag was -%c\n\n", attribute->flag);        }        break;      } else if (*run != '-' && ts->type == 'v') {        // Missing -e flag        // Report the new syntax but setup the attribute        // as if we are using it                fprintf(stderr, "Nam syntax has changed: %s", line);        fprintf(stderr, "Please use this format in the future.\n");        fprintf(stderr, "v -t <time> -e <tcl expression>\n\n");        attribute_type = 'e';      } else {        // Eat the dash and set the current attribute        run++;        attribute_type = *run;        run++;      }      //Match in Table      attribute = ts->attributes;      while (attribute != NULL) {        if (attribute_type == attribute->flag) {          break;        }        attribute = attribute->next;      }      //Read in Value      if (attribute) {        // Eat the flag and whitespace, to end on the value        run = eatSpaces(run);        run = attribute->parseValue(run, line);        attribute->seen = true;      } else {        fprintf(stderr, "Unknown Flag -%c in: %s\n", attribute_type, line);        // Skip to next attribute        while (*run != '-' && *run != '\n') {          run++;        }      }      run = eatSpaces(run);    }    // Check for required attributes    attribute = ts->attributes;    while (attribute != NULL) {      if (attribute->required && !attribute->seen) {        success = false;        fprintf(stderr, "Missing required flag -%c in: %s\n", attribute->flag, line);      }      attribute = attribute->next;      }  } else {    fprintf(stderr, "Unknown nam event id type: %s\n", line);    success = false;  }  return success;}//---------------------------------------------------------------------////---------------------------------------------------------------------TraceSyntax * ParseTable::addTraceSyntax(char id, char * label) {  TraceSyntax * ts;    if (!syntax_list) {    // Create list and add this as the first member    ts = new TraceSyntax(id, label);    syntax_list =  ts;    syntax_list_tail = ts;  } else {    // Check for duplicates    ts = syntax_list;    while (ts) {      if (ts->type == id) {        break;      }      ts = ts->next;    }    if (!ts) {      // Add it to the end of the list      ts = new TraceSyntax(id, label);      syntax_list_tail->next = ts;      syntax_list_tail = ts;    }  }    return ts;}//---------------------------------------------------------------------////---------------------------------------------------------------------char *eatSpaces(char * marker) {  while (*marker == ' ' || *marker == '\t') {    marker++;   }  return marker;}//---------------------------------------------------------------------////---------------------------------------------------------------------char *advanceToSpace(char * marker) {  while (!isspace(*marker)) {    marker++;   }  return marker;}//---------------------------------------------------------------------////---------------------------------------------------------------------char * advanceToNextFlag(char * marker) {  while (*marker != '-' && *marker != '\n' && *marker != '\0') {    marker++;  }  return marker;}//---------------------------------------------------------------------////---------------------------------------------------------------------char * advanceToEndofLine(char * marker) {  while (*marker != '\n' && *marker != '\0') {    marker++;  }  return marker;}//---------------------------------------------------------------------// char *// ParseTable::parse_string(char *orig, char * output)//   - Extracts the string after a flag in a nam animation line.//   - Removes any double quotes, null terminates the string //     and copies it into the output variable.//   - Returns the location after the extracted string in the original//     nam animation line.//   - Requires that the original pointer points to the start of //     the string.////   - Strings can be double quoted or have no quotes////     Note: May need to add in \r check for Micro$oft Windows//---------------------------------------------------------------------char *extractString(char * original, char * output) {  char * run; // run along the string  int count = 0;  // size of the copied string, should be less than MAXNAME  run = original;  // Skip over first double quote, if any  if (*run == '"') {    run++;    // Copy over to output    while (count < MAXNAME &&           *run != '"' &&           *run != '\n' &&           *run != '\r') {      output[count] = *run;      run++;      count++;    }      // Skip over last double quote, if any    if (*run == '"') {      run++;    }  } else {    // Copy over to output    while (count < MAXNAME &&           *run != '"' &&           *run != ' ' &&           *run != '\n' &&           *run != '\r') {      output[count] = *run;      run++;      count++;    }  }  // Null Terminate the String  if (count < MAXNAME) {    output[count] = '\0';    count++;  } else {    count--;    output[count] = '\0';  }        return run;}

⌨️ 快捷键说明

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