home *** CD-ROM | disk | FTP | other *** search
/ PDA Software Library / pdasoftwarelib.iso / PSION / COMMS / PSIONMAI / PMFULLSO / SUNMAIL / LL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-04  |  9.8 KB  |  417 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "project.h"
  4.  
  5. /* Start of Global data */
  6.  
  7. /* pointers to the in and out list and the list we are currently working on */
  8. struct ll * inlist ;
  9. struct ll * outlist ;
  10. struct ll * currlist ;
  11.  
  12. /* End of Global data */
  13.  
  14. /* Start of function definitions */
  15.  
  16.  
  17. /* commands to manipulate the linked list */
  18. struct ll * llnew() ;
  19. struct ll * llnofind() ;
  20.  
  21. /* End of function definitions */
  22.  
  23. /* start of actual code */
  24.  
  25. /* start of linked list code */
  26.  
  27. /* display the usual header information */
  28. disphdrs(llptr, startno, endno)
  29. struct ll * llptr ;
  30. int startno, endno ;
  31. {
  32.     int mask ;
  33.     if (lldbg == TRUE)
  34.         printf("CALL: disphdrs (llptr = OMITTED, starton = %d, endno = %d)", startno, endno) ;
  35.     /* if llptr is inlist include from, otherwise include to */
  36.     if (llptr == inlist)
  37.         mask = PFROM ;
  38.     else
  39.         mask = PTO ;
  40.     /* add the other stuff */
  41.     mask = mask | PNO | PSUBJECT | PREAD | PACTIVE ;
  42.     /* startno MUST be 1 or higher */
  43.     if (startno < 1)
  44.         startno = 1 ;
  45.     /* endno should be less or equal to llptr->count */
  46.     if (endno > llptr->count)
  47.         endno = llptr->count ;
  48.     llprint(llptr, mask, startno, endno) ;
  49. }
  50. /* print the entire ll list */
  51. lldmpall(llptr)
  52. struct ll * llptr ;
  53. {
  54.     while (llptr != NULL)
  55.     {
  56.         lldump(llptr) ;
  57.         llptr = llptr->next ;
  58.     }
  59. }
  60. /* print the list at start ll, according to the mask, between the numbers startno and end no */
  61. llprint(startll, mask, startno, endno)
  62. struct ll * startll ;
  63. int mask, startno, endno ;
  64. {
  65.     if (lldbg == TRUE)
  66.         printf("CALL: llprint (startll = OMITTED, mask = %x, startno = %d, endno = %d)", mask, startno, endno) ;
  67.     while (startll != NULL)
  68.     {
  69.         if ((startll->no >= startno) && (startll->no <= endno))
  70.         {
  71.             /* should we be printing this record ? */
  72.             if ((mask & PACTIVE) && (startll->status == ACTIVE))
  73.                 llprinta(startll, mask) ;
  74.             else if ((mask & PIGNORE) && (startll->status == IGNORE))            llprinta(startll, mask) ;
  75.             else if ((mask & PDELETED) && (startll->status == DELETED))
  76.                 llprinta(startll, mask) ;
  77.         }
  78.         startll = startll->next ;
  79.     }
  80. }
  81.  
  82. /* print the structure according to the mask */
  83. llprinta(llptr, mask)
  84. struct ll * llptr ;
  85. int mask ;
  86. {
  87.     char tmp[100] ;
  88.     char outline[1024] ;
  89.     if (lldbg == TRUE)
  90.         printf("CALL: llprinta (llptr = OMITTED, mask = %x", mask) ;
  91.     outline[0] = '\0' ;
  92.     /* print llptr according to the mask */
  93.     if (mask & PNO)
  94.     {
  95.         sprintf(tmp, "%d", llptr->no) ;
  96.         strcat(outline, tmp) ;
  97.         strcat(outline, " ") ;
  98.     }
  99.     if (mask & PDATAFILE)
  100.     {
  101.         strcat(outline, llptr->datafile) ;
  102.         strcat(outline, " ") ;
  103.     }
  104.     if (mask & PTO)
  105.     {
  106.         strcat(outline, llptr->to) ;
  107.         strcat(outline, " ") ;
  108.     }
  109.     if (mask & PFROM)
  110.     {
  111.         strcat(outline, llptr->from) ;
  112.         strcat(outline, " ") ;
  113.     }
  114.     if (mask & PSUBJECT)
  115.     {
  116.         strcat(outline, llptr->subject) ;
  117.         strcat(outline, " ") ;
  118.     }
  119.     if (mask & PCC)
  120.     {
  121.         strcat(outline, llptr->cc) ;
  122.         strcat(outline, " ") ;
  123.     }
  124.     if(mask & PBCC)
  125.     {
  126.         strcat(outline, llptr->bcc) ;
  127.         strcat(outline, " ") ;
  128.     }
  129.     if (mask & PSTATUS)
  130.     {
  131.         if (llptr->status == ACTIVE)
  132.         {
  133.             strcat(outline, "ACTIVE") ;
  134.             strcat(outline, " ") ;
  135.         }
  136.         else if (llptr->status == IGNORE)
  137.         {
  138.             strcat(outline, "IGNORE") ;
  139.             strcat(outline, " ") ;
  140.         }
  141.         else if (llptr->status == DELETED)
  142.         {
  143.             strcat(outline, "DELETED") ;
  144.             strcat(outline, " ") ;
  145.         }
  146.     }
  147.     if (mask & PREAD)
  148.     {
  149.         if (llptr->read == RD)
  150.         {
  151.             strcat(outline, "READ") ;
  152.             strcat(outline, " ") ;
  153.         }
  154.         else
  155.         {
  156.             strcat(outline, "NEW") ;
  157.             strcat(outline, " ") ;
  158.         }
  159.     }
  160.     if (mask & PCOUNT)
  161.     {
  162.         sprintf(tmp, "%d", llptr->count) ;
  163.         strcat(outline, tmp);
  164.         strcat(outline, " ") ;
  165.     }
  166.     /* print the newline */
  167.     printf("%s\n", outline) ;
  168. }
  169. /* print the current ll entry */
  170. lldump(llptr)
  171. struct ll * llptr ;
  172. {
  173.     if (lldbg == TRUE)
  174.         printf("CALL: lldump (llptr = OMITTED)") ;
  175.     if (llptr == NULL)
  176.     {
  177.         printf("Pointer is NULL") ;
  178.         return ;
  179.     }
  180.     printf("Datafile is: %s", llptr->datafile) ;
  181.     printf("To is: %s", llptr->to) ;
  182.     printf("From is: %s", llptr->from ) ;
  183.     printf("Subject is: %s", llptr->subject) ;
  184.     printf("CC is: %s", llptr->cc) ;
  185.     printf("Bcc is: %s", llptr->bcc) ;
  186.     /* status */
  187.     if (llptr->status == ACTIVE)
  188.         printf("Status is: ACTIVE") ;
  189.     else if (llptr->status == DELETED)
  190.         printf("Status is: DELETED") ;
  191.     else if (llptr->status == IGNORE)
  192.         printf("Status is: IGNORE") ;
  193.     else
  194.         printf("Status is invalid (%d)", llptr->status) ;
  195.     /* read */
  196.     if (llptr->read == RD)
  197.         printf("Read is: RD") ;
  198.     else if (llptr->read == NEW)
  199.         printf("Read is: NEW") ;
  200.     else
  201.         printf("Read is invalid (%d)", llptr->read) ;
  202.     printf("No is: %d", llptr->no) ;
  203.     printf("Count is: %d", llptr->count) ;
  204.     if (llptr->mydata == NULL)
  205.         printf("Mydata is: NULL") ;
  206.     else
  207.     {
  208.         printf("Mydata->myaddr is: %s", llptr->mydata->myaddr) ;
  209.         printf("Mydata->mypath is: %s", llptr->mydata->mypath) ;
  210.     }
  211.     if (llptr->next == NULL)
  212.         printf("Next is: NULL") ;
  213.     else
  214.         printf("Next is: Non NULL") ;
  215. }
  216.  
  217. /* this command scans the linked lists looking for a deleted entry. the associated file is then deleted */
  218. prgemail(llptr)
  219. struct ll * llptr;
  220. {
  221.     struct ll * llstart ;
  222.     int ret ;
  223.     if (cmddbg == TRUE)
  224.         printf("CALL: prgemail (llstart = OMITTED)") ;
  225.     llstart = llptr ;
  226.     while(llptr != NULL)
  227.     {
  228.         if(llptr->status == DELETED)
  229.         {
  230.             ret = delfile(llptr, llstart) ;
  231.             if (ret == FILEERR)
  232.             {
  233.                 printf("FILE ERROR: prgemail, error in deleting message file %s", llptr->datafile) ;
  234.                 return(FILEERR) ;
  235.             }
  236.         }
  237.         llptr = llptr->next ;
  238.     }
  239.     return(TRUE) ;
  240. }
  241. /* fill in a ll entry based on the arguments */
  242. llfill(llptr, datafile, to, from, subject, cc, bcc, status, read, no)
  243. struct ll * llptr;
  244. char * datafile, * to, * from, * subject, * cc, * bcc ;
  245. int status, read, no;
  246. {
  247.     if (lldbg == TRUE)
  248.         printf("CALL llfill (llptr = OMITTED, datafile = %s, to = %s, from = %s, subject = %s, cc = %s, bcc = %s, status = %d, read = %d, no = %d)", datafile, to, from, subject, cc, bcc, status, read, no) ;
  249.     strcpy(llptr->datafile, datafile) ;
  250.     strcpy(llptr->to, to) ;
  251.     strcpy(llptr->from, from) ;
  252.     strcpy(llptr->subject, subject) ;
  253.     strcpy(llptr->cc, cc) ;
  254.     strcpy(llptr->bcc, bcc) ;
  255.     llptr->status = status ;
  256.     llptr->read = read ;
  257.     llptr->no = no ;
  258.     if (lldbg == TRUE)
  259.     {
  260.         printf("filled in structure is");
  261.         lldump(llptr) ;
  262.     }
  263. }
  264. /* find a list entry based on the number */
  265. struct ll * llnofind(no, llstart)
  266. int no ;
  267. struct ll * llstart ;
  268. {
  269.     struct ll * llcurrnt ;
  270.     if (lldbg == TRUE)
  271.         printf("CALL: llnofind(no = %d, llstart = OMITTED)", no) ;
  272.     llcurrnt = llstart ;
  273.     while(llcurrnt->no != no)
  274.     {
  275.         if (lldbg == TRUE)
  276.         {
  277.             printf("llnofind is working on") ;
  278.             lldump(llcurrnt) ;
  279.         }
  280.         if(llcurrnt->next == NULL)
  281.         {
  282.             if (lldbg == TRUE)
  283.                 printf("llnofind returns NULL");
  284.             return(NULL) ;
  285.         }
  286.         llcurrnt = llcurrnt->next ;
  287.  
  288.     }
  289.     /* to have got here we must havea match if we could not find a match we would already havereturned NULL */
  290.     if (lldbg == TRUE)
  291.     {
  292.         printf("llnofind returns the following");
  293.         lldump(llcurrnt) ;
  294.     }
  295.     return(llcurrnt) ;
  296. }
  297.         
  298. /* this adds the newll to the end of the list at startll */
  299. lladd(newll, startll)
  300. struct ll * newll, * startll ;
  301. {
  302.     struct ll * llcurrnt ;
  303.     if (lldbg == TRUE)
  304.         printf("lladd (newll = OMITTED, startll = OMITTED)") ;
  305.     llcurrnt = startll ;
  306.     /* scan down the list lokking for NULL) */
  307.     while(llcurrnt->next != NULL)
  308.     {
  309.         llcurrnt = llcurrnt->next ;
  310.     }
  311.     /* we are at the end of the list add the entry */
  312.     llcurrnt->next = newll ;
  313.     /* increment the total in the list counter, held in the first entry in the list only */
  314.     startll->count ++ ;
  315. }
  316. /* this function creates the initial in and out list entries */
  317. llinit()
  318. {
  319.     if (lldbg == TRUE)
  320.         printf("CALL: llinit()") ;
  321.     inlist = llnew() ;
  322.     outlist = llnew() ;
  323.     inlist->mydata = (struct mydata *) calloc((size_t) 1, (size_t) sizeof(struct mydata)) ;
  324.     outlist->mydata = (struct mydata *) calloc((size_t) 1, (size_t) sizeof(struct mydata)) ;
  325. }
  326.  
  327. /* linked list functions */
  328. /* llnew, create space and fill with defaults */
  329. struct ll * llnew()
  330. {
  331.     struct ll * llptr;
  332.     if (lldbg == TRUE)
  333.         printf("CALL: llnew()") ;
  334.     llptr = (struct ll *) calloc((size_t) 1, (size_t) sizeof(struct ll)) ;
  335.     llptr->datafile[0] = '\0' ;
  336.     llptr->to[0] = '\0' ;
  337.     llptr->from[0] = '\0' ;
  338.     llptr->subject[0] = '\0' ;
  339.     llptr->cc[0] = '\0' ;
  340.     llptr->bcc[0] = '\0' ;
  341.     llptr->status = IGNORE ;
  342.     llptr->read = NEW ;
  343.     llptr->next = NULL ;
  344.     llptr->no = 0 ;
  345.     llptr->count = 0 ;
  346.     llptr->mydata = NULL ;
  347.     return(llptr) ;
  348. }
  349. llcopy (out, in)
  350. struct ll * out, * in;
  351. {
  352.     if (lldbg == TRUE)
  353.     {
  354.         printf("CALL: llcopy (in = OMITTED, out = OMITTED)") ;
  355.         printf("input is ") ;
  356.         lldump(in) ;
  357.     }
  358.     /* copy the strings but status etc remains untouched */
  359.     strcpy(out->datafile, in->datafile) ;
  360.     strcpy(out->to, in->to) ;
  361.     strcpy(out->from, in->from) ;
  362.     strcpy(out->subject, in->subject) ;
  363.     strcpy(out->cc, in->cc) ;
  364.     strcpy(out->bcc, in->bcc) ;
  365.     if (lldbg == TRUE)
  366.     {
  367.         printf("output is ") ;
  368.         lldump(out) ;
  369.     }
  370. }
  371. /* llfree, free llptr and everything it points to */
  372. llfree (llptr)
  373. struct ll * llptr ;
  374. {
  375.     struct ll * llnext;
  376.     if (lldbg == TRUE)
  377.         printf("CALL: llfree(llptr = OMITTED)");
  378.     /* free the mydata section only on the first item */
  379.     free(llptr->mydata) ;
  380.     llnext = llptr;
  381.     while(llptr != NULL)
  382.     {
  383.         llnext = llptr->next ;
  384.         free(llptr) ;
  385.         llptr = llnext ;
  386.     }
  387. }
  388. /* is mailno in the list and marked as ACTIVE ? */
  389. llvalid(mailno, llptr)
  390. int mailno ;
  391. struct ll * llptr ;
  392. {
  393.     if (lldbg == TRUE)
  394.         printf("CALL: llvalid(mailno = %d, llptr = OMITTED)", mailno) ;
  395.     llptr = llnofind(mailno, llptr) ;
  396.     if (llptr != NULL)
  397.     {
  398.         if (llptr->status != ACTIVE)
  399.         {
  400.             printf("%d is not an active message", mailno) ;
  401.             return(FALSE) ;
  402.         }
  403.         else
  404.         {
  405.             return(TRUE) ;
  406.         }
  407.     }
  408.     else
  409.     {
  410.         printf("%d is not a valid message", mailno) ;
  411.         return(FALSE) ;
  412.     }
  413. }
  414.  
  415. /* end of linked list code */
  416.  
  417.