#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "pi-macros.h"
#include "pi-expense.h"
Include dependency graph for expense.c:

Go to the source code of this file.
Functions | |
| void | free_Expense (Expense_t *expense) |
| int | unpack_Expense (Expense_t *expense, unsigned char *buffer, int len) |
| int | pack_Expense (Expense_t *expense, unsigned char *record, int len) |
| int | unpack_ExpenseAppInfo (ExpenseAppInfo_t *appinfo, unsigned char *record, size_t len) |
| int | pack_ExpenseAppInfo (ExpenseAppInfo_t *appinfo, unsigned char *record, size_t len) |
| int | unpack_ExpensePref (ExpensePref_t *pref, unsigned char *record, int len) |
| int | pack_ExpensePref (ExpensePref_t *p, unsigned char *record, int len) |
Variables | |
| char * | ExpenseSortNames [] = { "Date", "Type", NULL } |
| char * | ExpenseDistanceNames [] = { "Miles", "Kilometers", NULL } |
| char * | ExpensePaymentNames [] |
| char * | ExpenseTypeNames [] |
| void free_Expense | ( | Expense_t * | expense | ) |
Definition at line 69 of file expense.c.
References Expense::amount, Expense::attendees, Expense::city, Expense::note, and Expense::vendor.
Referenced by main().
00070 { 00071 if (expense->note != NULL) { 00072 free(expense->note); 00073 expense->note = NULL; 00074 } 00075 00076 if (expense->amount != NULL) { 00077 free(expense->amount); 00078 expense->amount = NULL; 00079 } 00080 00081 if (expense->city != NULL) { 00082 free(expense->city); 00083 expense->city = NULL; 00084 } 00085 00086 if (expense->vendor != NULL) { 00087 free(expense->vendor); 00088 expense->vendor = NULL; 00089 } 00090 00091 if (expense->attendees != NULL) { 00092 free(expense->attendees); 00093 expense->attendees = NULL; 00094 } 00095 }
| int pack_Expense | ( | Expense_t * | expense, | |
| unsigned char * | record, | |||
| int | len | |||
| ) |
Definition at line 217 of file expense.c.
References Expense::amount, Expense::attendees, buf, Expense::city, Expense::currency, Expense::date, Expense::note, Expense::payment, set_byte, set_short, Expense::type, and Expense::vendor.
Referenced by main(), and test_expense().
00218 { 00219 int destlen = 6 + 1 + 1 + 1 + 1 + 1; 00220 unsigned char *buf = record; 00221 00222 if (expense->amount) 00223 destlen += strlen(expense->amount); 00224 if (expense->vendor) 00225 destlen += strlen(expense->vendor); 00226 if (expense->city) 00227 destlen += strlen(expense->city); 00228 if (expense->attendees) 00229 destlen += strlen(expense->attendees); 00230 if (expense->note) 00231 destlen += strlen(expense->note); 00232 00233 if (!record) 00234 return destlen; 00235 if (len < destlen) 00236 return 0; 00237 00238 set_short(buf, 00239 ((expense->date.tm_year - 4) << 9) | ((expense->date.tm_mon + 00240 1) << 5) | expense->date. 00241 tm_mday); 00242 buf += 2; 00243 set_byte(buf, expense->type); 00244 set_byte(buf + 1, expense->payment); 00245 set_byte(buf + 2, expense->currency); 00246 set_byte(buf + 3, 0); /* gapfill */ 00247 buf += 4; 00248 00249 if (expense->amount) { 00250 strcpy((char *)buf, expense->amount); 00251 buf += strlen((char *)buf); 00252 } else { 00253 set_byte(buf, 0); 00254 } 00255 buf++; 00256 00257 if (expense->vendor) { 00258 strcpy((char *)buf, expense->vendor); 00259 buf += strlen((char *)buf); 00260 } else { 00261 set_byte(buf, 0); 00262 } 00263 buf++; 00264 00265 if (expense->city) { 00266 strcpy((char *)buf, expense->city); 00267 buf += strlen((char *)buf); 00268 } else { 00269 set_byte(buf, 0); 00270 } 00271 buf++; 00272 00273 if (expense->attendees) { 00274 strcpy((char *)buf, expense->attendees); 00275 buf += strlen((char *)buf); 00276 } else { 00277 set_byte(buf, 0); 00278 } 00279 buf++; 00280 00281 if (expense->note) { 00282 strcpy((char *)buf, expense->note); 00283 buf += strlen((char *)buf); 00284 } else { 00285 set_byte(buf, 0); 00286 } 00287 buf++; 00288 00289 return (buf - record); 00290 }
| int pack_ExpenseAppInfo | ( | ExpenseAppInfo_t * | appinfo, | |
| unsigned char * | record, | |||
| size_t | len | |||
| ) |
Definition at line 342 of file expense.c.
References ExpenseAppInfo::category, ExpenseAppInfo::currencies, ExpenseCustomCurrency::name, pack_CategoryAppInfo(), ExpenseCustomCurrency::rate, set_byte, ExpenseAppInfo::sortOrder, and ExpenseCustomCurrency::symbol.
Referenced by main(), and test_expense().
00344 { 00345 int i, 00346 destlen = 2 + (16 + 4 + 8) * 4; 00347 unsigned char *start = record; 00348 00349 i = pack_CategoryAppInfo(&appinfo->category, record, len); 00350 if (!record) 00351 return i + destlen; 00352 if (!i) 00353 return i; 00354 record += i; 00355 len -= i; 00356 if (len < destlen) 00357 return 0; 00358 set_byte(record, appinfo->sortOrder); 00359 set_byte(record + 1, 0); /* gapfill */ 00360 record += 2; 00361 for (i = 0; i < 4; i++) { 00362 memcpy(record, appinfo->currencies[i].name, 16); 00363 record += 16; 00364 memcpy(record, appinfo->currencies[i].symbol, 4); 00365 record += 4; 00366 memcpy(record, appinfo->currencies[i].rate, 8); 00367 record += 8; 00368 } 00369 00370 return (record - start); 00371 }
Here is the call graph for this function:

| int pack_ExpensePref | ( | ExpensePref_t * | p, | |
| unsigned char * | record, | |||
| int | len | |||
| ) |
Definition at line 436 of file expense.c.
References ExpensePref::allowQuickFill, ExpensePref::attendeeFont, ExpensePref::currencies, ExpensePref::currentCategory, ExpensePref::defaultCurrency, ExpensePref::noteFont, ExpensePref::saveBackup, set_byte, set_short, ExpensePref::showAllCategories, ExpensePref::showCurrency, and ExpensePref::unitOfDistance.
Referenced by main().
00437 { 00438 int i; 00439 unsigned char *start = record; 00440 00441 (void) len; 00442 00443 set_short(record, p->currentCategory); 00444 record += 2; 00445 set_short(record, p->defaultCurrency); 00446 record += 2; 00447 set_byte(record, p->attendeeFont); 00448 record++; 00449 set_byte(record, p->showAllCategories); 00450 record++; 00451 set_byte(record, p->showCurrency); 00452 record++; 00453 set_byte(record, p->saveBackup); 00454 record++; 00455 set_byte(record, p->allowQuickFill); 00456 record++; 00457 set_byte(record, p->unitOfDistance); 00458 record++; 00459 for (i = 0; i < 5; i++) { 00460 set_byte(record, p->currencies[i]); 00461 record++; 00462 } 00463 /* Unknown values */ 00464 set_byte(record, 0xff); 00465 record++; 00466 set_byte(record, 0xff); 00467 record++; 00468 00469 set_byte(record, p->noteFont); 00470 record++; 00471 00472 return record - start; 00473 }
| int unpack_Expense | ( | Expense_t * | expense, | |
| unsigned char * | buffer, | |||
| int | len | |||
| ) |
Definition at line 110 of file expense.c.
References Expense::amount, Expense::attendees, Expense::city, Expense::currency, Expense::date, get_byte, get_short, Expense::note, Expense::payment, strdup(), Expense::type, and Expense::vendor.
Referenced by main(), and test_expense().
00111 { 00112 unsigned long d; 00113 unsigned char *start = buffer; 00114 00115 if (len < 6) 00116 return 0; 00117 00118 d = (unsigned short int) get_short(buffer); 00119 expense->date.tm_year = (d >> 9) + 4; 00120 expense->date.tm_mon = ((d >> 5) & 15) - 1; 00121 expense->date.tm_mday = d & 31; 00122 expense->date.tm_hour = 0; 00123 expense->date.tm_min = 0; 00124 expense->date.tm_sec = 0; 00125 expense->date.tm_isdst = -1; 00126 mktime(&expense->date); 00127 00128 expense->type = (enum ExpenseType) get_byte(buffer + 2); 00129 expense->payment = (enum ExpensePayment) get_byte(buffer + 3); 00130 expense->currency = get_byte(buffer + 4); 00131 00132 buffer += 6; 00133 len -= 6; 00134 00135 if (len < 1) 00136 return 0; 00137 00138 if (*buffer) { 00139 expense->amount = strdup((char *)buffer); 00140 buffer += strlen(expense->amount); 00141 len -= strlen(expense->amount); 00142 } else { 00143 expense->amount = 0; 00144 } 00145 buffer++; 00146 len--; 00147 00148 if (len < 1) 00149 return 0; 00150 00151 if (*buffer) { 00152 expense->vendor = strdup((char *)buffer); 00153 buffer += strlen(expense->vendor); 00154 len -= strlen(expense->vendor); 00155 } else { 00156 expense->vendor = 0; 00157 } 00158 buffer++; 00159 len--; 00160 00161 if (len < 1) 00162 return 0; 00163 00164 if (*buffer) { 00165 expense->city = strdup((char *)buffer); 00166 buffer += strlen(expense->city); 00167 len -= strlen(expense->city); 00168 } else { 00169 expense->city = 0; 00170 } 00171 buffer++; 00172 len--; 00173 00174 if (len < 1) 00175 return 0; 00176 00177 if (*buffer) { 00178 expense->attendees = strdup((char *)buffer); 00179 buffer += strlen(expense->attendees); 00180 len -= strlen(expense->attendees); 00181 } else { 00182 expense->attendees = 0; 00183 } 00184 buffer++; 00185 len--; 00186 00187 if (len < 1) 00188 return 0; 00189 00190 if (*buffer) { 00191 expense->note = strdup((char *)buffer); 00192 buffer += strlen(expense->note); 00193 len -= strlen(expense->note); 00194 } else { 00195 expense->note = 0; 00196 } 00197 00198 buffer++; 00199 len--; 00200 00201 return (buffer - start); 00202 }
Here is the call graph for this function:

| int unpack_ExpenseAppInfo | ( | ExpenseAppInfo_t * | appinfo, | |
| unsigned char * | record, | |||
| size_t | len | |||
| ) |
Definition at line 305 of file expense.c.
References ExpenseAppInfo::category, ExpenseAppInfo::currencies, get_byte, ExpenseCustomCurrency::name, ExpenseCustomCurrency::rate, ExpenseAppInfo::sortOrder, ExpenseCustomCurrency::symbol, and unpack_CategoryAppInfo().
Referenced by main(), and test_expense().
00307 { 00308 int i; 00309 unsigned char *start = record; 00310 00311 i = unpack_CategoryAppInfo(&appinfo->category, record, len); 00312 if (!i) 00313 return 0; 00314 record += i; 00315 len -= i; 00316 00317 appinfo->sortOrder = (enum ExpenseSort) get_byte(record); 00318 record += 2; 00319 for (i = 0; i < 4; i++) { 00320 memcpy(appinfo->currencies[i].name, record, 16); 00321 record += 16; 00322 memcpy(appinfo->currencies[i].symbol, record, 4); 00323 record += 4; 00324 memcpy(appinfo->currencies[i].rate, record, 8); 00325 record += 8; 00326 } 00327 return (record - start); 00328 }
Here is the call graph for this function:

| int unpack_ExpensePref | ( | ExpensePref_t * | pref, | |
| unsigned char * | record, | |||
| int | len | |||
| ) |
Definition at line 385 of file expense.c.
References ExpensePref::allowQuickFill, ExpensePref::attendeeFont, ExpensePref::currencies, ExpensePref::currentCategory, ExpensePref::defaultCurrency, get_byte, get_short, ExpensePref::noteFont, ExpensePref::saveBackup, ExpensePref::showAllCategories, ExpensePref::showCurrency, ExpensePref::unitOfDistance, and ExpensePref::unknown.
Referenced by main().
00386 { 00387 int i; 00388 unsigned char *start = record; 00389 00390 (void) len; 00391 00392 pref->currentCategory = get_short(record); 00393 record += 2; 00394 pref->defaultCurrency = get_short(record); 00395 record += 2; 00396 pref->attendeeFont = get_byte(record); 00397 record++; 00398 pref->showAllCategories = get_byte(record); 00399 record++; 00400 pref->showCurrency = get_byte(record); 00401 record++; 00402 pref->saveBackup = get_byte(record); 00403 record++; 00404 pref->allowQuickFill = get_byte(record); 00405 record++; 00406 pref->unitOfDistance = (enum ExpenseDistance) get_byte(record); 00407 record++; 00408 00409 for (i = 0; i < 5; i++) { 00410 pref->currencies[i] = get_byte(record); 00411 record++; 00412 } 00413 00414 for (i = 0; i < 2; i++) { 00415 pref->unknown[i] = get_byte(record); 00416 record++; 00417 } 00418 00419 pref->noteFont = get_byte(record); 00420 record++; 00421 00422 return (record - start); 00423 }
| char* ExpenseDistanceNames[] = { "Miles", "Kilometers", NULL } |
| char* ExpensePaymentNames[] |
| char* ExpenseSortNames[] = { "Date", "Type", NULL } |
| char* ExpenseTypeNames[] |
Initial value:
{ "Airfare", "Breakfast", "Bus", "Business Meals", "Car Rental",
"Dinner", "Entertainment", "Fax", "Gas", "Gifts", "Hotel",
"Incidentals", "Laundry", "Limo", "Lodging", "Lunch", "Mileage",
"Other", "Parking", "Postage", "Snack", "Subway", "Supplies",
"Taxi", "Telephone", "Tips", "Tolls", "Train"
}
Definition at line 48 of file expense.c.
Referenced by main().