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

📄 qfax.c

📁 使用efax的fax工具程序
💻 C
📖 第 1 页 / 共 2 页
字号:
	state = intext;        buf[j++] = c;	buf[j] = 0;      }      break;    /*     * This is the first space we've encountered in the text string,     * so we're trying to figure out whether we've got multiple words     * here (i.e. this is the full name), or whether this leads into     * a bracket/quote/parenthesis next (i.e. this is a single word,     * most likely the alias).  We'll skip all whitespace here.     */    case gotspace:      if (isspace(c))	state = gotspace;      else if (c == '(') {	state = inparen;	strcpy(alias, buf);	alias[strlen(alias)-1] = 0;	buf[j=0] = 0;      } else if (c == '<') {	state = inbracket;	strcpy(alias, buf);	alias[strlen(alias)-1] = 0;	buf[j=0] = 0;      } else if (c == '"') {	state = inquote;	strcpy(alias, buf);	alias[strlen(alias)-1] = 0;	buf[j=0] = 0;      } else {	state = infullname;	buf[j++] = c;	buf[j] = 0;      }      break;    /*     * At this stage we've encountered at least two words, so we know     * this can't be an alias or an e-mail address, thus we assume that     * this is the full name.  We just continue to read until we come     * to the end of the line, or we encounter a parenthesis or bracket.     * We ignore quotes here, treating them as part of the full name.     */    case infullname:      if (c == '(')      {	state = inparen;	strcpy(fullname, buf);	fullname[strlen(fullname)-1] = 0;	buf[j=0] = 0;      }      else if (c == '<')      {        state = inbracket;	strcpy(fullname, buf);	fullname[strlen(fullname)-1] = 0;	buf[j=0] = 0;      }      else       {	state = infullname;	buf[j++] = c;	buf[j] = 0;      }      break;    /*     * Here we've found an '@' in the middle of a string of characters,     * so we assume the preceding text is the alias, and since we're     * not interested in the host portion of the address, we can ignore     * everything to the end of the line, or until we encounter a     * parenthesis, bracket, or quote.     */    case ignoretext:      if (c == '(')      {	state = inparen;        buf[j=0] = 0;      }      else if (c == '<')      {        state = inbracket;        buf[j=0] = 0;      }      else if (c == '"')      {	state = inquote;	buf[j=0] = 0;      }      else	state = ignoretext;      break;    /*     * We've encountered an opening quotation mark, so we grab     * everything until we encounter a closing quotation.     */    case inquote:      if (c == '"') {	state = intext;	strcpy(quotes, buf);	buf[j=0] = 0;      } else if (c == '@') {   /* found alias, skip to closing '"' */	state = ignorequote;	strcpy(alias, buf);      } else {	state = inquote;	buf[j++] = c;	buf[j] = 0;      }      break;    /*     * We've found an '@' inside the quote, and hence we know the     * alias, so we assume the rest of the quote is just the host     * part of the address, and we ignore it.     */    case ignorequote:      if (c == '"')	state = intext;        buf[j=0] = 0;      break;    /*     * We've encountered an opening parenthesis, so we grab everything     * up to the closing parenthesis.     */    case inparen:      if (c == ')') {	state = intext;	strcpy(parentheses, buf);	buf[j=0] = 0;      } else if (c == '@') {  /* found alias, skip to closing ')' */	state = ignoreparen;	strcpy(alias, buf);      } else {	state = inparen;	buf[j++] = c;	buf[j] = 0;      }      break;    /*     * We've found an '@' inside the parentheses, so we know the     * alias now, and we're assuming the remainder of the text in the     * parentheses is the host part of the address, which we ignore.     */    case ignoreparen:      if (c == ')')	state = intext;        buf[j=0] = 0;      break;    /*     * We've encountered an opening angle bracket, so we grab everything     * up to the closing angle bracket.     */    case inbracket:      if (c == '>') {	state = intext;	strcpy(brackets, buf);	buf[j=0] = 0;      } else if (c == '@') {	state = ignorebracket;	strcpy(alias, buf);      } else {	state = inbracket;	buf[j++] = c;	buf[j] = 0;      }      break;    /*     * We've found an '@' inside the angle brackets, so we know the     * alias now, and we're assuming the remainder of the text in the     * angle brackets is the host part of the address, which we ignore.     */    case ignorebracket:      if (c == '>')	state = intext;        buf[j=0] = 0;      break;    /*     * At some point we encountered a character that wasn't expected,     * and very likely invalid, so we report a syntax error.     */    case error:    default:      state = error;      buf[j=0] = 0;    }     }  /*   * Here we check the end-state to see where we ended up at the end   * of the "From:" line.   */  switch(state) {  /*   * We ended while still parsing text, which means we either never   * found any brackets, quotes, or parentheses, or that we got past   * all of these.   *   * Basically, if we ended normally (after a closing parenthesis,   * quote, or bracket), buf should be empty.  If buf is not empty,   * we assume it represents the full name if we already have an   * alias, otherwise we take it to be the alias.   */  case intext:    if (*buf)      if (*alias)        strcpy(fullname, buf);      else        strcpy(alias, buf);    break;  /*   * We got the alias from the address, but we never found a full name.   * Nonetheless, that's still a valid condition.   */  case ignoretext:    break;  /*   * We ended while still looking for the closing quotation mark.   */  case inquote:    /*   * We ended while still looking for the closing parenthesis.   */  case inparen:  case ignoreparen:  /*   * We ended while still looking for the closing angle bracket.   */  case inbracket:  case ignorebracket:  /*   * We couldn't parse the string's syntax.   */  case error:  case start:  default:    errors = 1;  }  /*   * Now the hard part--figuring out what the alias and full name might   * be, if these aren't already determined.  We use some simple rules   * thumb here, but it generally guesses correctly :)   */  if (!*alias) {    if (*brackets) {      strcpy(alias, brackets);      *brackets = 0;    }    else if (*parentheses) {      strcpy(alias, parentheses);      *parentheses = 0;    }  }  if (!*fullname) {    if (*quotes) {      strcpy(fullname, quotes);      *quotes = 0;    }    else if (*parentheses) {      strcpy(fullname, parentheses);      *parentheses = 0;    }    else if (*brackets) {      strcpy(fullname, brackets);      *brackets = 0;    }  }  return(errors);}void main(void){  Fax f;  read_config(&f);         /* load fax parameters */  read_mail(&f);           /* parse the mail headers */  if (strcmp(f.fperson.username, "unknown")) {    lookup_db(&f);         /* look up recipient in the phonebook */    make_fax(&f);          /* turn the mail into a fax */    make_cover(&f);        /* create a fax cover page */    insert_cover(&f);      /* make the cover page #1 */    queue_fax(&f);         /* throw the completed fax onto the spool */    cleanup(&f);           /* delete any garbage we created */    dispatch(&f);          /* send the fax immediately, if allowed */    exit(EXIT_SUCCESS);    /* we're outta here...in a good way */  }  exit(EXIT_FAILURE);      /* we're outta here...in a bad way */}

⌨️ 快捷键说明

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