home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / biz / misc / banker / src / common.h < prev    next >
C/C++ Source or Header  |  1993-12-17  |  12KB  |  536 lines

  1. /*
  2.  * common.h
  3.  */
  4.  
  5. /* $Id: common.h,v 1.4 1993/08/28 19:39:39 beust Exp $ */
  6.  
  7. #include <stdio.h>
  8. #include <exec/types.h>
  9. #include <strings.h>
  10. #include <libraries/mui.h>
  11.  
  12.  
  13. /* Libraries definitions */
  14. #include <libraries/locale.h>
  15. #include <libraries/gadtools.h>
  16.  
  17. /* Graphics */
  18. #include <graphics/displayinfo.h>
  19. #include <intuition/gadgetclass.h>
  20. #include <workbench/startup.h>
  21. #include <workbench/workbench.h>
  22.  
  23. /* Prototypes */
  24. #include <clib/locale_protos.h>
  25. #include <clib/exec_protos.h>
  26. #include <clib/intuition_protos.h>
  27. #include <clib/gadtools_protos.h>
  28. #include <clib/dos_protos.h>
  29. #include <clib/iffparse_protos.h>
  30. #include <clib/utility_protos.h>
  31. #include <clib/wb_protos.h>
  32. #include <clib/icon_protos.h>
  33. #include <clib/muimaster_protos.h>
  34.  
  35. /* Pragmas */
  36. #include <pragmas/muimaster_pragmas.h>
  37.  
  38. /* Personal includes */
  39. #include "locale_strings.h"
  40. #include "database.h"
  41.  
  42. /* Icon */
  43. extern struct IconBase *IconBase;
  44.  
  45. /* Locale */
  46. extern struct LocaleBase *LocaleBase;
  47. extern struct Locale *MyLocale;
  48. extern struct Catalog *MyCatalog;
  49.  
  50. /* General definitions */
  51. #define NEW(v, t) v = (t *) malloc(sizeof(t))
  52. #define STREQUAL(s1, s2) (strcmp(s1, s2) == 0)
  53.  
  54. #define isblank(c) (c == ' ' || c == '\t')
  55. #define myAssert(p)
  56. #ifdef cedric
  57. #define D(x) { printf("%s:%d--- ", __FILE__, __LINE__); x; }
  58. #else
  59. #define D(x)
  60. #endif
  61.  
  62.  
  63. /* The main structure */
  64. #define ENTRYFORMATSTRING "%c %8s|%8s| %-6.2f |%8s|%8s|%35s"
  65. #define AUTOFORMATSTRING  "%c %8s    %3d %3d %3d %3d   %30s"
  66.  
  67. #define DATEL sizeof(struct DateStamp)
  68. #define TRANSACTIONL 80
  69. #define AMOUNTL 32
  70. #define CHECKNUMBERL 20
  71. #define IMPUTATIONL 80
  72. #define REASONL 80
  73.  
  74. typedef struct _Automatic {
  75.    char *formattedString;            /* the entry once it is formatted */
  76.    struct DateStamp first;          /* first occurring for this automatic entry */
  77.    struct DateStamp last;               /* last... */
  78.    ULONG repeatDays;                   /* repeat each days */
  79.    ULONG repeatWeeks;                 /* ... weeks */
  80.    ULONG repeatMonths;               /* ... months */
  81.    ULONG repeatYears;               /* ... years */
  82.    char transaction[REASONL];      /* reason to give */
  83.    char imputation[IMPUTATIONL];  /* category where this automatic falls into */
  84.    char amount[AMOUNTL];         /* the amount of the transaction */
  85. } *Automatic;
  86.  
  87. typedef struct _Entry {
  88.    char *formattedString;            /* the entry once it is formatted */
  89.    struct DateStamp date;
  90.    char transaction[TRANSACTIONL];
  91.    char checkNumber[CHECKNUMBERL];
  92.    char amount[AMOUNTL];          /* the amount of the transaction */
  93.    char imputation[IMPUTATIONL]; /* category where this automatic falls into */
  94.    char reason[REASONL];        /* reason to give */
  95.    char validated;             /* boolean actually */
  96.    Automatic generatedBy;     /* if this entry comes from an automatic */
  97.    char fake;                /* if true, this entry was generated automatically */
  98.    char pad[3];             /* pad the rest for a long aligned struct */
  99.          
  100. } *Entry;
  101.  
  102. #define ENTRY_SIZE DATEL+TRANSACTIONL+AMOUNTL+CHECKNUMBERL+IMPUTATIONL+REASONL+4
  103. #define AUTO_SIZE sizeof(struct DateStamp) * 2 + sizeof(ULONG) * 4 +\
  104.                   AMOUNTL + IMPUTATIONL + REASONL
  105.  
  106. typedef struct _Entries {
  107.    Entry *list;
  108.    Automatic *automatic;
  109. } *Entries;
  110.  
  111. typedef float TotalType;
  112.  
  113. /* This structure to hold the names of my listview */
  114. /* Since a list can be displayed several times, I must do smart allocation */
  115. /* here (e.g. see if there's enough room in the previous list for the new */
  116. /* one, else allocate another one). Initialize it to NULL and pass it to */
  117. /* buildList() */ 
  118.  
  119. struct SmartAlloc {
  120.   int count;
  121.   char **strings;
  122. };
  123.  
  124. /*****************
  125.  * The format structures
  126.  *****************/
  127.  
  128. enum Fields {
  129.    DATEFIELD = 1 << 0, AMOUNTFIELD = 1 << 1, TRANSACTIONFIELD = 1 << 2,
  130.    REASONFIELD = 1 << 3, CHECKNUMBERFIELD = 1 << 4, IMPUTATIONFIELD = 1 << 5
  131. };
  132.  
  133. /*
  134.  ** A column in the list view is represented by the following structure
  135.  ** The first field is the list of the selected fields, coded as
  136.  ** a string (e.g. "\01\03" = DATE REASON. numberOfFields would be 2 for
  137.  ** this column. 
  138.  */
  139.  
  140.  
  141. #define MAX_FIELDS 6
  142. #define MAX_COLUMNS 20
  143.  
  144.  
  145. struct ColumnListEntry {
  146.    char fields[MAX_FIELDS + 1];       /* the fields for this column */
  147.    int numberOfFields;
  148.    char *format;
  149. };
  150.  
  151. struct ListEntry {
  152.    int numberOfColumns;
  153.    struct ColumnListEntry col[MAX_COLUMNS];
  154.    char *after;
  155. };
  156.  
  157. extern struct ListEntry DisplayEntryFormat[];     /* common.c */
  158.  
  159. struct StringAspect {
  160.    enum Fields field[6];         /* what field */
  161.    char *format[6];              /* string in printf format */
  162.    char *after;                  /* the possible trailing string */
  163.    int numberOfFields;           /* number of fields the user wants */
  164. };
  165.  
  166. extern struct StringAspect PrintFormatStructure,
  167.                            ExportFormatStructure,
  168.                            DisplayFormatStructure;    /* common.c */
  169.  
  170. /*********
  171.  * The GUI structure
  172.  *********/
  173.  
  174. /*
  175. typedef void (*MenuCallbackPointer_t)() ;
  176. */
  177.  
  178. #define MENU_ITEM_COUNT 20
  179. #define MENU_CALLBACK(f) void f(Gui_t gui, Entries entries)
  180.  
  181. typedef struct _Gui {
  182.   APTR app;
  183.   APTR mainWindowObject, getEntryWindowObject,
  184.        automaticWindowObject, clearWindowObject, listWindowObject;
  185.   APTR geDate, geCheckNumber, geTransaction, geImputation, geAmount,
  186.        geReplace, geReason;
  187.   APTR auFrom, auTo, auAmount, auDays, auWeeks, auMonths, auYears,
  188.        auReason, auImputation, auListviewObject, auListObject,
  189.        auNew, auAdd, auReplace, auDelete;
  190.   APTR liCycleObject, liListviewObject, liListObject,
  191.        liValidatedObject, liTotalObject;
  192.  
  193.   struct SmartAlloc entrySA, autoSA;
  194.   void **menuFunctions;
  195. } *Gui_t;
  196.  
  197. extern struct _Gui Gui;    /* gui.c */
  198. extern struct Library *MUIMasterBase;      /* gui.c */
  199.  
  200.  
  201.  
  202. /*********
  203.  * Time variables
  204.  *********/
  205.  
  206. extern struct timerequest *AutosaveTR; /* (common.c) */
  207. extern LONG AutosaveSignal;            /* (common.c) */
  208. extern struct MsgPort *AutosavePort;   /* (common.c) */
  209.  
  210.  
  211. /*********
  212.  * IFF defines
  213.  *********/
  214.  
  215. #define ID_FTXT MAKE_ID('F','T','X','T')
  216. #define ID_CHRS MAKE_ID('C','H','R','S')
  217. #define ID_AUTO MAKE_ID('A','U','T','O')
  218.  
  219. /*********
  220.  * The output
  221.  *********/
  222.  
  223. #define BANKEROUTPUTWINDOW "CON:0/10/640/100"
  224. extern FILE *BankerWindow;    /* common.c */
  225.  
  226.  
  227. /*********
  228.  * Command line parsing
  229.  *********/
  230.  
  231. /* Command line structure (passed to ReadArgs()) */
  232. #define OPTIONSFILENAME "s:.bankerconfig"    /* default name for the config file */
  233.  
  234. struct CommandLineStruct {
  235.    char *language;
  236.    char *filename;
  237.    char *optionsFile;
  238. };
  239. extern struct CommandLineStruct CL_Struct;  /* (common.c) */
  240. extern char *CL_Usage; /* (common.c) */
  241.  
  242. /* The fields in the options file */
  243. struct WindowDesc {
  244.    BOOL isOpen;
  245. };
  246.  
  247.  
  248. /*********
  249.  * Options file parsing
  250.  *********/
  251.  
  252. struct OptionsFileStruct {
  253.    struct WindowDesc mainWindow;
  254.    struct WindowDesc automatic;
  255.    struct WindowDesc getEntry;
  256.    struct WindowDesc list;
  257.    int autoSave;
  258.    char *defaultDate;
  259.    char *dateFormat;
  260.    char *displayFormat;
  261.    char *exportFormat;
  262.    char *printFormat;
  263. };
  264. extern struct OptionsFileStruct OF_Struct;  /* (common.c) */
  265.  
  266. extern int UniqueID;
  267.  
  268. double atof();
  269. #define STRINGTOTOTAL(s) atof(s)
  270.  
  271. extern struct _Entry LastSelectedEntry;   /* getentry.c */
  272. extern BOOL CanReplace;     /* getentry.c */
  273.  
  274. extern Entries MainList;   /* the big Database (main.c) */
  275.  
  276. extern BOOL FileModified; /* true if file has been modified (common.c) */
  277.  
  278. /*
  279.  ** common.c
  280.  */
  281.  
  282. extern BOOL FileModified;              /* True if file was modified */
  283. extern char FileName[128];            /* last accessed filename  */
  284. extern char ExportFileName[128];     /* exported file name  */
  285. extern char PrintFileName[128];     /* print filename */
  286. extern char Pattern[128];          /* pattern for file requester  */
  287. extern char ExportPattern[128];   /* pattern for export requester  */
  288. extern char PrintPattern[128];   /* pattern for print requester  */
  289.  
  290.  
  291.  
  292. /*********
  293.  * MUI
  294.  *********/
  295.  
  296. #define ID_MAINWINDOW 0x4489
  297. #define ID_GETENTRYWINDOW 0x448a
  298. #define ID_AUTOMATICWINDOW 0x448b
  299. #define ID_LISTWINDOW 0x448c
  300.  
  301. /*********
  302.  * Prototypes
  303.  *********/
  304.  
  305.  
  306. /*
  307.  * gui.c
  308.  */
  309.  
  310. int
  311. buildGui(Gui_t gs, Entries entries, struct OptionsFileStruct *ofStruct);
  312. /* Build the GUI and main loop for the events */
  313.  
  314.  
  315. /*
  316.  * automatic.c
  317.  */
  318.  
  319. void
  320. openAutomaticWindow(Gui_t gui, Entries entries);
  321. /* Open the automatic window and set the gadgets to default value */
  322.  
  323. void
  324. clearAutomaticGadgets(Gui_t gui);
  325. /* Set the gadgets to their default values */
  326.  
  327. void
  328. newAutomatic(Gui_t gui, Entries entries);
  329. /* Clear the gadgets to enter a new automatic */
  330.  
  331. void
  332. replaceAutomatic(Gui_t gui, Entries entries);
  333. /* Replace the previously selected automatic with the one in the gadgets */
  334.  
  335. void
  336. addAutomatic(Gui_t gui, Entries entries);
  337. /* Add the automatic in the gadgets to the database */
  338.  
  339. void
  340. deleteAutomatic(Gui_t gui, Entries entries, Automatic automatic);
  341. /* If automatic == NULL, retrieve the automatic from the gadgets */
  342.  
  343. void
  344. editAutomatic(Gui_t gui, Automatic automatic);
  345. /* Edit an automatic entry, open the window if necessary */
  346.  
  347.  
  348. /*
  349.  * getentry.c
  350.  */
  351.  
  352. void
  353. openEntryWindow(Gui_t gui, Entries entries);
  354. /* Open the getentry window and set the gadgets to default value */
  355.  
  356. Entry
  357. getEntryFromGadgets(Gui_t gui);
  358. /* Return the entry currently in the gadgets */
  359.  
  360. void
  361. clearGetentryGadgets(Gui_t gui);
  362. /* Clear the gadgets */
  363.  
  364. void
  365. addEntry(Gui_t gui, Entries entries);
  366. /* Add the entry currently in the gadgets to the database */
  367.  
  368. void
  369. replaceEntry(Gui_t gui, Entries entries);
  370. /* Replace the latest selected entry with the one in the gadgets */
  371.  
  372. void
  373. editEntry(Gui_t gui, Entry entry);
  374. /* Edit the selected entry */
  375.  
  376.  
  377. /*
  378.  * list.c
  379.  */
  380.  
  381.  
  382. void
  383. openListWindow(Gui_t gui, Entries entries);
  384. /* Open the list window */
  385.  
  386. void
  387. simpleDisplayList(Gui_t gui, Entries entry);
  388. /* Display the database in the listview */
  389.  
  390. void
  391. fullDisplayList(Gui_t gui, Entries entry);
  392. /* Display the database in the listview */
  393.  
  394. void
  395. handleValidate(Gui_t gui, Entries entries, Entry entry);
  396. /* Validate the specified entry */
  397.  
  398. void
  399. handleEdit(Gui_t gui, Entries entries, Entry entry);
  400. /* Edit the specified entry, open the getentry window if necessary */
  401.  
  402. void
  403. handleDelete(Gui_t gui, Entries entries, Entry entry);
  404. /* Delete the specified entry */
  405.  
  406.  
  407. /*
  408.  * io.c
  409.  */
  410.  
  411. void
  412. openFile(Gui_t gui, Entries entries, char *file);
  413.  
  414. void
  415. saveFile(Entries entries, char *filename);
  416.  
  417. void
  418. writeOptionsFile(Gui_t gui);
  419. /* Get the window configuration and write it to disk */
  420.  
  421. void
  422. writeTextFile(Entries entries, char *file, struct StringAspect *sa);
  423.  
  424. void
  425. readOptionsFile();
  426.  
  427. /*
  428.  * common.c
  429.  */
  430.  
  431. void
  432. closeAll();
  433.  
  434. void
  435. openLibraries(Entries *entries);
  436.  
  437. char
  438. getSignificantCharacter(int n);
  439.  
  440. char *
  441. getString(int n);
  442.  
  443. void
  444. myMsg1(char *s1);
  445.  
  446. void
  447. myMsg2(char *s1, char *s2);
  448.  
  449. void
  450. myMsg3(char *s1, char *s2, int n);
  451.  
  452. char *
  453. crashFileName(char *filename);
  454.  
  455. void
  456. readEnvironment(int argc, char **argv);
  457. /* Read the command line (or the WBMessage), and take appropriate actions */
  458. /* (open file, etc...) */
  459.  
  460. struct DateStamp *
  461. myStrToDate(char *dateString);
  462.  
  463. char *
  464. myDateToStr(struct DateStamp *ds);
  465.  
  466. /*
  467.  * common2.c
  468.  */
  469.  
  470. void
  471. addEntryDatabase(Entries entries, Entry entry, char fake, Automatic generatedBy);
  472.  
  473. TotalType
  474. computeValidatedTotal(Entries list);
  475.  
  476. TotalType
  477. computeTotal(Entries list);
  478.  
  479. void
  480. buildDataBase(Entries entries);
  481.  
  482. char *
  483. returnFormattedString(struct StringAspect *sa, Entry entry);
  484.  
  485. void
  486. sortList(Entries list);
  487.  
  488. int
  489. daysInNYears(ULONG days, ULONG n, ULONG year);
  490.  
  491. int
  492. daysInNMonths(ULONG days, ULONG n, ULONG month, ULONG year);
  493.  
  494. char *
  495. printEntry(Entries list, int number, char *s);
  496.  
  497. void
  498. printEntries(Entries list);
  499.  
  500. struct StringAspect *
  501. parseFormatString(char *string);
  502. /* [[@n &n] keyword string] * */
  503.  
  504. void
  505. clearDataBase(Entries entries);
  506.  
  507. void
  508. getFileName(Gui_t gui, char *initial, char *hail, char *result, char *pattern);
  509.  
  510. int
  511. showRequester(Gui_t gui, char *title, char *text, char *choices);
  512.  
  513. char *
  514. myPathPart(char *path);
  515.  
  516. void
  517. buildList(Gui_t gui, Entries entries, BOOL entry, BOOL sorted,
  518.       struct SmartAlloc *sn);
  519.  
  520.  
  521. /*
  522.  * menu.c
  523.  */
  524.  
  525. void
  526. addToNewMenu(struct NewMenu *nm, Gui_t gui,
  527.          UBYTE type, STRPTR label, STRPTR shortCut,
  528.          int id, APTR callback, int n);
  529.  
  530. MENU_CALLBACK(menuOpen);
  531. MENU_CALLBACK(menuSave);
  532. MENU_CALLBACK(menuSaveAs);
  533. MENU_CALLBACK(menuPrint);
  534. MENU_CALLBACK(menuExport);
  535. MENU_CALLBACK(menuSavePrefs);
  536.