int main(int argc, char **argv, char **envp) { int ch; signal(SIGHUP, wakeup); initsetproctitle(argc, argv, envp); if(chdir(BBSHOME)) return 1; while((ch = getopt(argc, argv, "qh")) != -1) { switch(ch) { case 'q': listQueue(); return 0; default: usage(); return 0; } } for(;;) { sendMail(); setproctitle("outmail: sleeping"); sleep(60 * 3); /* send mail every 3 minute */ } return 0; }
// // parses a multi token assumes no leading whitespace PARSE_TOKEN *parse_multi_token(const char **format) { const char *fmt = *format; bool close_found = FALSE; // skip our opening { fmt++; // skip any leading whitespace while(isspace(*fmt)) fmt++; // make our multi-token PARSE_TOKEN *multi_token = newParseToken(PARSE_TOKEN_MULTI); // parse all of our tokens and add them to the multi-list while(*fmt != '\0' && !close_found) { PARSE_TOKEN *one_token = parse_one_datatype(&fmt); // did we parse the token alright? if(one_token != NULL) { listQueue(multi_token->token_list, one_token); // up the positioning of format *format = fmt; } // syntactic error. break out! else break; // skip any whitespace while(isspace(*fmt)) fmt++; // have we encountered the closing bracket? if(*fmt == '}') close_found = TRUE; } // if we never found a close, or we didn't parse any arguments, // delete the token because it was not finished if(close_found == FALSE || listSize(multi_token->token_list) == 0) { deleteParseToken(multi_token); multi_token = NULL; } // otherwise, skip the closing bracket and up the position of format else { fmt++; *format = fmt; } return multi_token; }
// // builds up a list of variables out of the token list, and arguments. If we // encounter an error and we need to show it to the looker, do so. LIST *compose_variable_list(CHAR_DATA *looker, LIST *tokens, char *args, char *err_buf) { LIST *variables = newList(); LIST_ITERATOR *tok_i = newListIterator(tokens); PARSE_TOKEN *tok = NULL; bool error = FALSE; bool optional_found = FALSE; // go through our list of tokens, and try dealing with the args ITERATE_LIST(tok, tok_i) { PARSE_VAR *var = NULL; // did we just encounter an optional value? if(tok->type == PARSE_TOKEN_OPTIONAL) { optional_found = TRUE; continue; } // can we still use tokens to process stuff? if(*args != '\0') var = use_one_parse_token(looker, tok, &args, &error, err_buf); // we haven't found an "optional" marker yet - this isn't allowed else if(optional_found == FALSE) error = TRUE; // we have found an "optional" marker. Just break out of the loop else break; // if use of the token returned a new variable, append it if(var != NULL) listQueue(variables, var); // if we enountered an error, tell the person if neccessary else if(error == TRUE) { deleteListWith(variables, deleteParseVar); variables = NULL; break; } } deleteListIterator(tok_i);
// // breaks up a format string into its parts and returns a list of them LIST *decompose_parse_format(const char *format) { const char *fmt = format; bool error = FALSE; LIST *token_list = newList(); // try to parse all of our format down into tokens while(*fmt != '\0' && !error) { PARSE_TOKEN *token = parse_one_token(&fmt); // did the token parse OK? if(token != NULL) listQueue(token_list, token); else error = TRUE; } // did we encounter an error? if(error == TRUE) { deleteListWith(token_list, deleteParseToken); token_list = NULL; } return token_list; }