home *** CD-ROM | disk | FTP | other *** search
/ PDA Software Library / pdasoftwarelib.iso / PSION / COMMS / PSIONMAI / PMFULLSO / SUNMAIL / SCCS / S4.C < prev    next >
Encoding:
Text File  |  1995-07-04  |  9.5 KB  |  429 lines

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