ref: 15a7a70d93c42b675dda5057b6088fd3c920dfbd
parent: 7bc4d4f57bc35956c69039e92ebef1737f973e95
author: Julien Blanchard <julien@typed-hole.org>
date: Mon Nov 30 05:03:53 EST 2020
Formatting
--- a/toe.c
+++ b/toe.c
@@ -4,8 +4,8 @@
typedef struct Query
{
- char *domain;
- char *user;
+ char *domain;
+ char *user;
} Query;
@@ -12,72 +12,71 @@
void
toe(Query *query)
{
- char *naddr;
- char *line;
- int fd;
- Biobuf out, body;
+ char *naddr;
+ char *line;
+ int fd;
+ Biobuf out, body;
- naddr = netmkaddr(query->domain, "tcp", "79");
- fd = dial(naddr, 0, 0, 0);
- if(fd < 0){
- print("unable to connect to %s: %r", query->domain);
- return;
- }
+ naddr = netmkaddr(query->domain, "tcp", "79");
+ fd = dial(naddr, 0, 0, 0);
+ if(fd < 0){
+ print("unable to connect to %s: %r", query->domain);
+ return;
+ }
- if (query->user == nil) {
- fprint(fd, "\r\n");
- } else {
- fprint(fd, "%s\r\n", query->user);
- }
+ if (query->user == nil) {
+ fprint(fd, "\r\n");
+ } else {
+ fprint(fd, "%s\r\n", query->user);
+ }
- Binit(&body, fd, OREAD);
- Binit(&out, 1, OWRITE);
+ Binit(&body, fd, OREAD);
+ Binit(&out, 1, OWRITE);
- while((line = Brdstr(&body, '\n', 0)) != nil){
- Bprint(&out, "%s", line);
- free(line);
- }
+ while((line = Brdstr(&body, '\n', 0)) != nil){
+ Bprint(&out, "%s", line);
+ free(line);
+ }
- Bflush(&out);
- Bflush(&body);
- close(fd);
- free(query);
+ Bflush(&out);
+ Bflush(&body);
+ close(fd);
+ free(query);
}
Query *
mk_query(char *query_str)
{
- char *user, *domain;
- Query *new_query = malloc(sizeof(Query));
+ char *user, *domain;
+ Query *new_query = malloc(sizeof(Query));
- if (query_str[0] == '@') {
- user = nil;
- domain = query_str + 1;
- } else if (strstr(query_str, "@") == nil) {
- user = query_str;
- domain = "localhost";
- } else {
- user = strtok(query_str, "@");
- domain = strtok(nil, "@");
- }
+ if (query_str[0] == '@') {
+ user = nil;
+ domain = query_str + 1;
+ } else if (strstr(query_str, "@") == nil) {
+ user = query_str;
+ domain = "localhost";
+ } else {
+ user = strtok(query_str, "@");
+ domain = strtok(nil, "@");
+ }
- new_query->user = user;
- new_query->domain = domain;
+ new_query->user = user;
+ new_query->domain = domain;
- return new_query;
+ return new_query;
}
void
main(int argc, char **argv)
{
- if( argc == 2 ) {
- Query *query = mk_query(argv[1]);
-
- toe(query);
- exits(0);
- } else if( argc > 2 ) {
- print("Too many arguments supplied.\n");
- } else {
- print("Usage: toe [user]@server.\n");
- }
+ if( argc == 2 ) {
+ Query *query = mk_query(argv[1]);
+ toe(query);
+ exits(0);
+ } else if( argc > 2 ) {
+ print("Too many arguments supplied.\n");
+ } else {
+ print("Usage: toe [user]@server.\n");
+ }
}