ptokenizer::token_t ptokenizer::get_token() { while (true) { token_t ret = get_token_internal(); if (ret.is_type(ENDOFFILE)) return ret; if (ret.is(m_tok_comment_start)) { do { ret = get_token_internal(); } while (ret.is_not(m_tok_comment_end)); } else if (ret.is(m_tok_line_comment)) { skipeol(); } else if (ret.str() == "#") { skipeol(); } else return ret; } }
void netlist_parser::skipws() { while (unsigned char c = getc()) { switch (c) { case ' ': case 9: case 10: case 13: break; case '#': skipeol(); // treat preprocessor defines as comments break; case '/': c = getc(); if (c == '/') { skipeol(); } else if (c == '*') { int f=0; while (!eof() ) { c = getc(); if (f == 0 && c == '*') f=1; else if (f == 1 && c== '/' ) break; else f=0; } } break; default: ungetc(); return; } } }
void netlist_parser::skipws() { while (unsigned char c = getc()) { switch (c) { case ' ': case 9: case 10: case 13: break; case '/': c = getc(); if (c == '/') { skipeol(); } else if (c == '*') { int f=0; while ((c = getc()) != 0 ) { if (f == 0 && c == '*') f=1; else if (f == 1 && c== '/' ) break; else f=0; } } break; default: ungetc(); return; } } }
int include(const char *filename) { struct includeline *script, *se, *sp; char input[256]; /* big enough? */ int argc,res; char **argv, *cp; int fd, flags, line; if (((fd = rel_open(filename, NULL, O_RDONLY)) == -1)) { command_errmsg = command_errbuf; snprintf(command_errbuf, 256, "cannot find \"%s\"", filename); return(CMD_ERROR); } /* * Read the script into memory. */ script = se = NULL; line = 0; while (fgets(input, sizeof(input), fd) != NULL) { line++; flags = 0; if(strlen(input) == sizeof(input) - 1 && !iseol(input[sizeof(input) - 2])) { printf("WARNING: %s: %s: Line too long: truncating; have:\n", __func__, filename); printf("%s\n", input); skipeol(fd); } /* Discard comments */ if (strncmp(input+strspn(input, " "), "\\ ", 2) == 0) continue; cp = input; /* Echo? */ if (input[0] == '@') { cp++; flags |= SL_QUIET; } /* Error OK? */ if (input[0] == '-') { cp++; flags |= SL_IGNOREERR; } /* Allocate script line structure and copy line, flags */ sp = malloc(sizeof(struct includeline) + strlen(cp) + 1); sp->text = (char *)sp + sizeof(struct includeline); strcpy(sp->text, cp); sp->flags = flags; sp->line = line; sp->next = NULL; if (script == NULL) { script = sp; } else { se->next = sp; } se = sp; } close(fd); /* * Execute the script */ argv = NULL; res = CMD_OK; for (sp = script; sp != NULL; sp = sp->next) { #if 0 /* print if not being quiet */ if (!(sp->flags & SL_QUIET)) { prompt(); printf("%s\n", sp->text); } #endif /* Parse the command */ if (!parse(&argc, &argv, sp->text)) { if ((argc > 0) && (perform(argc, argv) != 0)) { /* normal command */ printf("%s: %s\n", argv[0], command_errmsg); if (!(sp->flags & SL_IGNOREERR)) { res=CMD_ERROR; break; } } free(argv); argv = NULL; } else { printf("%s line %d: parse error\n", filename, sp->line); res=CMD_ERROR; break; } } if (argv != NULL) free(argv); while(script != NULL) { se = script; script = script->next; free(se); } return(res); }