home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************
- /*
- /* File SAMPLE.C
- /*
- /* Program Sample for Fax/PM API use.
- /*
- /* Last modif February 5, 1993
- /*
- /* Copyright (c) Microformatic S.A. 1993
- /*
- /*****************************************************************************/
-
- /*****************************************************************************
- /* Includes
- /*****************************************************************************/
-
- #define INCL_DOS
- #define INCL_ERROR
- #define INCL_ERRORS
- #define INCL_PM
- #include <os2.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <memory.h>
-
- #include <recip.h>
- #include <group.h>
-
- /*****************************************************************************
- /* Includes
- /*****************************************************************************/
-
- #define MAX 10
- #define GROUP_NAME "All names"
- #define NEW_GROUP_NAME "New All names"
-
-
- /*****************************************************************************
- /* Global variables
- /*****************************************************************************/
-
- FaxRecipient *MyPhoneBook;
- FaxGroup * MyGroup;
-
- CHAR szArg[512];
- CHAR szArg1[80];
- CHAR szArg2[80];
-
-
- /*****************************************************************************
- /*
- /* Function LISTALL
- /*
- /* Description Lists the names and groups defined in the Fax/PM phone book.
- /*
- /* Parameters none
- /*
- /* Return code none
- /*
- /****************************************************************************/
-
- VOID APIENTRY LISTALL()
- {
- APIRET rc; /* return code for function calls */
- ULONG ulLen; /* length of required memory */
- PSZ pszGroups; /* pointer to group list */
- PSZ pszNames; /* pointer to name list */
- ULONG i ; /* index in a list */
-
- /***************************************************************************
- /* List all groups : issue a first call to get the length of the required
- /* memory, then issue a second call to actually retrieve the information.
- /**************************************************************************/
- rc = FaxGroup_GetAllNames(MyGroup, (PSZ) 0, &ulLen);
- if (rc != FAX_PHONEBOOK_OK) {
- ulLen=0 ;
- };
- printf("-----------------------> Groups in Fax/PM phone book :\n");
- if (ulLen != 0) {
- pszGroups = (PSZ) malloc(ulLen);
- rc = FaxGroup_GetAllNames(MyGroup, (PSZ) pszGroups, &ulLen);
- if (rc != FAX_PHONEBOOK_OK) {
- printf("LISTALL: GetAllNames rc: %d\n", rc);
- free(pszGroups);
- return;
- };
- for (i=0; pszGroups[i] != 0; ) {
- printf("\t>>> %s\n", &pszGroups[i]);
- i = i + strlen(&pszGroups[i]) + 1;
- } /* endfor */
- free(pszGroups);
- } else {
- printf("No group defined !\n");
- }; /* endif */
-
-
- /***************************************************************************
- /* List all names : issue a first call to get the length of the required
- /* memory, then issue a second call to actually retrieve the information.
- /**************************************************************************/
- rc = FaxRecipient_GetAllNames(MyPhoneBook, (PSZ) 0, &ulLen);
- if (rc != FAX_PHONEBOOK_OK) {
- ulLen=0 ;
- };
- printf("-----------------------> Names in Fax/PM phone book :\n");
- if (ulLen != 0) {
- pszNames = (PSZ) malloc(ulLen);
- rc = FaxRecipient_GetAllNames(MyPhoneBook, (PSZ) pszNames, &ulLen);
- if (rc != FAX_PHONEBOOK_OK) {
- printf("LISTALL: GetAllRecipientNames rc: %d\n", rc);
- free(pszNames);
- return;
- };
- for (i=0; pszNames[i] != 0; ) {
- printf("\t>>> %s\n", &pszNames[i]);
- i = i + strlen(&pszNames[i]) + 1;
- } /* endfor */
- } else {
- printf("No name defined !\n");
- return;
- }; /* endif */
- printf("-----------------------> End of list\n");
- free(pszNames);
- return;
- }
-
-
- /*****************************************************************************
- /*
- /* Function GO1
- /*
- /* Description Process 1 parameter command line
- /*
- /* Parameters none
- /*
- /* Return code none
- /*
- /****************************************************************************/
-
- VOID APIENTRY GO1()
- {
- APIRET rc; /* return code for function calls */
- ULONG ulLen; /* length of required memory */
- ULONG i ; /* index in a list */
- PSZ p1; /* parameter 1 */
- PSZ p2; /* parameter 2 */
-
- p1 = (PSZ) 0;
- p2 = (PSZ) 0;
-
- /***************************************************************************
- /* Delete a group
- /**************************************************************************/
- p1 = strstr(szArg1, "-DN:");
- if (p1 != (PSZ) 0) {
- printf("Delete group name: %s\n", &p1[4]);
- rc = FaxGroup_Delete(MyGroup, &p1[4]);
- printf("Delete group name: %s rc:%ld\n", &p1[4], rc);
- return;
- };
-
- /***************************************************************************
- /* Get a recipient from the phonebook
- /**************************************************************************/
- p1 = strstr(szArg1, "-LN:");
- if (p1 != (PSZ) 0) {
- rc = FaxRecipient_Get(MyPhoneBook, &p1[4]);
- if (rc != FAX_PHONEBOOK_OK) {
- printf("Get recipient: %s rc:%ld\n", &p1[4], rc);
- return;
- };
- rc = FaxRecipient_GetTel(MyPhoneBook, (PSZ) 0, &ulLen);
- if (rc != FAX_PHONEBOOK_OK) {
- printf("Get fax phone number for: %s rc:%ld\n", &p1[4], rc);
- };
- p2 = (PSZ) malloc(ulLen);
- rc = FaxRecipient_GetTel(MyPhoneBook, (PSZ) p2, &ulLen);
- printf("Name: %s\nFax phone number: %s\n", &p1[4], p2);
- free(p2);
- return;
- };
-
- /***************************************************************************
- /* Get the list of recipients is a group
- /**************************************************************************/
- p1 = strstr(szArg1, "-LG:");
- if (p1 != (PSZ) 0) {
- rc = FaxGroup_GetGroupContents(MyGroup,
- (PSZ) 0,
- &ulLen,
- &p1[4]);
- if (rc == FAX_PHONEBOOK_GROUP_NOTFOUND) {
- printf("Group: %s not found rc: %ld\n", &p1[4], rc);
- return;
- };
- if (rc != FAX_PHONEBOOK_OK) {
- printf("Group: %s not found error rc: %ld\n", &p1[4], rc);
- return;
- };
- p2 = (PSZ) malloc(ulLen);
- rc = FaxGroup_GetGroupContents(MyGroup,
- (PSZ) p2,
- &ulLen,
- &p1[4]);
- if (rc != FAX_PHONEBOOK_OK) {
- printf("Group: %s not found error rc: %ld\n", &p1[4], rc);
- return;
- };
- printf("Group: %s contents:\n", &p1[4]);
- for (i=0; p2[i] != 0; ) {
- printf("\t>>> %s\n", &p2[i]);
- i = i + strlen(&p2[i]) + 1;
- } /* endfor */
- printf("end Group: %s contents:\n", &p1[4]);
- free(p2);
- return;
- };
-
- /***************************************************************************
- /* Delete a group
- /**************************************************************************/
- p1 = strstr(szArg1, "-DG:");
- if (p1 != (PSZ) 0) {
- rc = FaxGroup_Delete(MyGroup, &p1[4]);
- if (rc == FAX_PHONEBOOK_GROUP_NOTFOUND) {
- printf("Delete group: %s rc:%ld (Group unknown !)\n", &p1[4], rc);
- return;
- };
- if (rc == FAX_PHONEBOOK_OK) {
- printf("Delete group: %s error rc:%ld\n", &p1[4], rc);
- return;
- };
- printf("Delete group: %s rc:%ld\n", &p1[4], rc);
- return;
- };
-
- return;
- }
-
-
- /*****************************************************************************
- /*
- /* Function GO2
- /*
- /* Description Process 2 parameters command line
- /*
- /* Parameters none
- /*
- /* Return code none
- /*
- /****************************************************************************/
-
- VOID APIENTRY GO2()
- {
- APIRET rc; /* return code for function calls */
- ULONG ulLen; /* length of required memory */
- PSZ p1; /* parameter 1 */
- PSZ p2; /* parameter 2 */
-
- /***************************************************************************
- /* Add recipient in the phonebook
- /**************************************************************************/
- p1 = strstr(szArg1, "-AN:");
- if (p1 != (PSZ) 0) {
- rc = FaxRecipient_SetName(MyPhoneBook, &p1[4]);
- rc = FaxRecipient_SetTel(MyPhoneBook, szArg2);
- rc = FaxRecipient_Create(MyPhoneBook);
- if (rc != FAX_PHONEBOOK_OK) {
- printf("Add recipient name: %s error rc: %ld\n", &p1[4], rc);
- return;
- };
- printf("Add recipient name: %s Ok\n", &p1[4]);
- return;
- };
-
- /***************************************************************************
- /* Add recipient in a group
- /**************************************************************************/
- p1 = strstr(szArg1, "-NG:");
- if (p1 != (PSZ) 0) {
- rc = FaxGroup_AddName(MyGroup, szArg2, &p1[4]);
- if (rc != FAX_PHONEBOOK_OK) {
- printf("Add recipient %s to group: %s error rc: %ld", &p1[4], szArg2, rc);
- return;
- };
- printf("Add recipient %s to group: %s Ok\n", &p1[4], szArg2);
- return;
- };
-
- /***************************************************************************
- /* Update recipient
- /**************************************************************************/
- p1 = strstr(szArg1, "-UN:");
- if (p1 != (PSZ) 0) {
- rc = FaxRecipient_SetName(MyPhoneBook, &p1[4]);
- rc = FaxRecipient_SetTel(MyPhoneBook, szArg2);
- rc = FaxRecipient_Update(MyPhoneBook);
- if (rc != FAX_PHONEBOOK_OK) {
- printf("Update recipient name: %s error rc: %ld\n", &p1[4], rc);
- return;
- };
- printf("Update recipient name: %s Ok\n", &p1[4]);
- return;
- };
-
- /***************************************************************************
- /* Delete name from a group
- /**************************************************************************/
- p1 = strstr(szArg1, "-SG:");
- if (p1 != (PSZ) 0) {
- rc = FaxGroup_DeleteName(MyGroup, szArg2, &p1[4]);
- if (rc == FAX_PHONEBOOK_GROUP_NOTFOUND) {
- printf("Delete recipient: %s in group: %s, group not found\n", &p1[4], szArg2);
- return;
- };
- if (rc != FAX_PHONEBOOK_OK) {
- printf("Delete recipient: %s in group: %s error rc:%ld\n", &p1[4], szArg2, rc);
- return;
- };
- printf("Delete recipient: %s in group: %s Ok\n", &p1[4], szArg2);
- return;
- };
-
-
- return;
- }
-
- /*****************************************************************************
- /*
- /* Function main
- /*
- /* Description main function : check parameters and take appropriate action.
- /*
- /* Parameters int argc : arguments count
- /* char * argv[] : array of string pointers
- /*
- /* Return code 0
- /*
- /****************************************************************************/
-
- int _Optlink main ( int argc, char* argv [] ) {
-
- /***************************************************************************
- /* Initialize all the objects
- /**************************************************************************/
- FaxRecipientNewClass(0,0);
- FaxGroupNewClass(0,0);
- MyPhoneBook = _somNew(_FaxRecipient);
- if (MyPhoneBook == 0) {
- printf("ERROR : Recipient Creation failed");
- return 0 ;
- };
- MyGroup = _somNew(_FaxGroup);
- if (MyGroup == 0) {
- printf("ERROR : Group Creation failed");
- return 0 ;
- };
- FaxRecipient_Setup(MyPhoneBook, "");
- FaxGroup_Setup(MyGroup, "");
-
- /***************************************************************************
- /* No argument : print command line syntax
- /**************************************************************************/
- if (argc == 1) {
- printf("Fax/PM API Sample Program - (c) Microformatic 1993\n\n") ;
- printf("Syntax :\n");
- printf(" commands used on Recipient names\n");
- printf(" -DN:name : delete a name\n");
- printf(" -AN:name phone : add name & phone\n");
- printf(" -LN:name : list a name\n");
- printf(" -NG:name group : add a name to group\n");
- printf(" -UN:name phone : update a name & phone\n");
- printf("\n");
- printf(" commands used on Group names\n");
- printf(" -LG:group : list a group contents\n");
- printf(" -DG:group : delete a group\n");
- printf(" -SG:name group : supress a name in a group\n");
- printf("\n");
- printf(" no parameters : list all groups & names\n");
- printf("\n");
- printf("\n");
- };
-
- /***************************************************************************
- /* Take the action depending on the number of parameters
- /**************************************************************************/
- szArg[0] = 0;
- if (argc == 1) {
- LISTALL();
- } else {
- if (argc == 2) {
- strcpy(szArg1, argv[1]);
- GO1();
- } else {
- strcpy(szArg1, argv[1]);
- strcpy(szArg2, argv[2]);
- GO2();
- }; /* endif */
- }; /* endif */
-
- return 0 ;
- }