Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

timestamp.c File Reference

#include <stdio.h>
#include "gwlib/gwlib.h"

Include dependency graph for timestamp.c:

Include dependency graph

Go to the source code of this file.

Functions

Octstrread_line (FILE *f, Octstr *buf)
int remove_long (long *p, Octstr *os)
int remove_prefix (Octstr *os, Octstr *prefix)
int parse_date (struct universaltime *ut, Octstr *os)
int main (void)


Function Documentation

int main void   ) 
 

Definition at line 143 of file timestamp.c.

References date_convert_universal(), GW_PANIC, gwlib_init(), gwlib_shutdown(), log_set_output_level(), octstr_create, octstr_destroy(), octstr_get_cstr, panic, parse_date(), and read_line().

00144 {
00145     struct universaltime ut;
00146     Octstr *os;
00147     Octstr *buf;
00148     
00149     gwlib_init();
00150     buf = octstr_create("");
00151     while ((os = read_line(stdin, buf)) != NULL) {
00152     if (parse_date(&ut, os) == -1)
00153         panic(0, "Bad line: %s", octstr_get_cstr(os));
00154     printf("%ld %s\n", date_convert_universal(&ut), octstr_get_cstr(os));
00155     octstr_destroy(os);
00156     }
00157 
00158     log_set_output_level(GW_PANIC);
00159     gwlib_shutdown();
00160 
00161     return 0;
00162 }

Here is the call graph for this function:

int parse_date struct universaltime ut,
Octstr os
[static]
 

Definition at line 120 of file timestamp.c.

References universaltime::day, universaltime::hour, universaltime::minute, universaltime::month, octstr_imm(), remove_long(), remove_prefix(), universaltime::second, and universaltime::year.

Referenced by main(), parse_progress_note_value(), parse_push_message_value(), parse_push_response_value(), and tokenize_date().

00121 {
00122     long pos;
00123 
00124     pos = 0;
00125     
00126     if (remove_long(&ut->year, os) == -1 ||
00127         remove_prefix(os, octstr_imm("-")) == -1 ||
00128     remove_long(&ut->month, os) == -1 ||
00129         remove_prefix(os, octstr_imm("-")) == -1 ||
00130     remove_long(&ut->day, os) == -1 ||
00131         remove_prefix(os, octstr_imm(" ")) == -1 ||
00132     remove_long(&ut->hour, os) == -1 ||
00133         remove_prefix(os, octstr_imm(":")) == -1 ||
00134     remove_long(&ut->minute, os) == -1 ||
00135         remove_prefix(os, octstr_imm(":")) == -1 ||
00136     remove_long(&ut->second, os) == -1 ||
00137         remove_prefix(os, octstr_imm(" ")) == -1)
00138         return -1;
00139     return 0;
00140 }

Here is the call graph for this function:

Octstr* read_line FILE *  f,
Octstr buf
[static]
 

Definition at line 74 of file timestamp.c.

References octstr_append_data(), octstr_copy, octstr_delete(), octstr_len(), and octstr_search_char().

Referenced by main().

00075 {
00076     Octstr *os;
00077     char cbuf[8*1024];
00078     size_t n;
00079     long pos;
00080     
00081     pos = octstr_search_char(buf, '\n', 0);
00082     while (pos == -1 && (n = fread(cbuf, 1, sizeof(cbuf), f)) > 0) {
00083     octstr_append_data(buf, cbuf, n);
00084     pos = octstr_search_char(buf, '\n', 0);
00085     }
00086 
00087     if (pos == -1) {
00088         pos = octstr_len(buf);
00089     if (pos == 0)
00090         return NULL;
00091     }
00092     os = octstr_copy(buf, 0, pos);
00093     octstr_delete(buf, 0, pos + 1);
00094 
00095     return os;
00096 }

Here is the call graph for this function:

int remove_long long *  p,
Octstr os
[static]
 

Definition at line 99 of file timestamp.c.

References octstr_delete(), and octstr_parse_long().

Referenced by parse_date().

00100 {
00101     long pos;
00102     
00103     pos = octstr_parse_long(p, os, 0, 10);
00104     if (pos == -1)
00105         return -1;
00106     octstr_delete(os, 0, pos);
00107     return 0;
00108 }

Here is the call graph for this function:

int remove_prefix Octstr os,
Octstr prefix
[static]
 

Definition at line 111 of file timestamp.c.

References octstr_delete(), octstr_len(), and octstr_ncompare().

Referenced by parse_date().

00112 {
00113     if (octstr_ncompare(os, prefix, octstr_len(prefix)) != 0)
00114         return -1;
00115     octstr_delete(os, 0, octstr_len(prefix));
00116     return 0;
00117 }

Here is the call graph for this function:

See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.