home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume2 / accell-text / Part5 < prev    next >
Encoding:
Internet Message Format  |  1991-08-07  |  38.1 KB

  1. From: ustel@well.UUCP (Mark Hargrove)
  2. Newsgroups: comp.sources.misc
  3. Subject: v02i054: Unify TEXT fields from ACCELL Part 5/5
  4. Message-ID: <7222@ncoast.UUCP>
  5. Date: 11 Feb 88 00:56:13 GMT
  6. Approved: allbery@ncoast.UUCP
  7.  
  8. Comp.sources.misc: Volume 2, Issue 54
  9. Submitted-By: "Mark Hargrove" <ustel@well.UUCP>
  10. Archive-Name: accell-text/Part5
  11.  
  12. #!/bin/sh
  13. # to extract, remove the header and type "sh filename"
  14. if `test ! -s ./README2`
  15. then
  16. echo "writing ./README2"
  17. cat > ./README2 << '\Rogue\Monster\'
  18. These are the c-hooks into the ACCELL amgr to use an editor
  19. to edit TEXT fields in the unify database. The file 'fedit.fs'
  20. is the accell forms script that all forms call to fire off the
  21. editor. 'fedit.fq' (uuencoded) is the form definition itself.
  22. Several global variables need to be set for fedit to work, these
  23. are documented in 'fedit.fs'.
  24.  
  25. The various functions provide the following capabilities:
  26.  
  27.     edit_txt() : Provides an interface to an editor (or any other
  28.              program) to modify text/binary fields. The 
  29.              routine will write the text field out into a
  30.              temporary file, passing the filename as an
  31.              argument to the editor program. The fields will
  32.              be null padded to an allocation boundary when 
  33.              written back to file.dbv. 
  34.  
  35.     display_txt() : Will display the first "line" of the 
  36.                 text in the text field into the 
  37.                 supplied screen string field.  The string
  38.             passed as the screen field argument must be
  39.             pre-allocated to whatever display length
  40.             you want.  The easiest way to do this is
  41.             to assign a strings of spaces to it just before
  42.             the call to display_txt().
  43.  
  44.     show_txt() : A read-only version of edit_txt().
  45.  
  46.     to_upper() : Convert the supplied string field to UPPER case.
  47.  
  48.     week_day() : Return the day of the week of today. (0=Sunday,
  49.              6=Saturday).
  50.  
  51.     day_of_week() : Return the day of the week of the supplied
  52.                 unify short date field.  We primarily use this
  53.             to detect Saturdays and Sundays when users are
  54.             entering due dates or tickler dates.
  55. \Rogue\Monster\
  56. else
  57.   echo "will not over write ./README2"
  58. fi
  59. if `test ! -s ./Makefile`
  60. then
  61. echo "writing ./Makefile"
  62. cat > ./Makefile << '\Rogue\Monster\'
  63. # custom AMGR makefile
  64.  
  65. SHELL=/bin/sh
  66. CC = cc 
  67. INCLUDE = $(UUINCLUDE)
  68. CFLAGS = $(INCLUDE) -g
  69. LFLAGS = # -Wl,-n    # used by NCR Tower32, forces shareable text
  70.  
  71. OBJS = chooktb.o disp_txt.o get_fld_no.o edit_txt.o show_txt.o text_size.o \
  72.          week_day.o to_upper.o 
  73.  
  74. amgr0887:    $(OBJS)
  75.         LDFLAGS="$LFLAGS"; export LDFLAGS; amgr.ld amgr0887 $(OBJS)
  76.  
  77. install:    
  78.         mv amgr0887 $(UNIFY)/../bin
  79.  
  80. clean:
  81.     /bin/rm *~ *.o
  82. \Rogue\Monster\
  83. else
  84.   echo "will not over write ./Makefile"
  85. fi
  86. if `test ! -s ./chooktb.c`
  87. then
  88. echo "writing ./chooktb.c"
  89. cat > ./chooktb.c << '\Rogue\Monster\'
  90. /**********************************************************************
  91. *
  92. *    chooktb.c - ACCELL/C-Language function hook tables
  93. *
  94. **********************************************************************/
  95.  
  96. #include <chookincl.h>
  97.  
  98. extern int display_txt();
  99. extern int edit_txt();
  100. extern int to_upper();
  101. extern int show_txt();
  102. extern int text_size();
  103. extern int week_day();
  104. extern int day_of_week();
  105. #ifdef CP
  106. extern int get_txt();
  107. extern int put_txt();
  108. #endif
  109.  
  110. CHOOK chooktb[] = 
  111.     {
  112.         { "display_txt", display_txt },
  113.         { "edit_txt", edit_txt },
  114.         { "to_upper", to_upper },
  115.         { "show_txt", show_txt },
  116.         { "text_size", text_size },
  117.         { "week_day", week_day },
  118.         { "day_of_week", day_of_week }
  119. #ifdef CP
  120.        ,{ "get_txt", get_txt },
  121.         { "put_txt", put_txt }
  122. #endif
  123.     };                        
  124.  
  125. /*** # elements in chook table DO NOT MODIFY ***/;
  126.  
  127. int nhooks = (sizeof(chooktb)/sizeof(*chooktb)); 
  128. \Rogue\Monster\
  129. else
  130.   echo "will not over write ./chooktb.c"
  131. fi
  132. if `test ! -s ./common.h`
  133. then
  134. echo "writing ./common.h"
  135. cat > ./common.h << '\Rogue\Monster\'
  136. /* stuff common to all language scripts */
  137.  
  138. #include "mesgnums.h"
  139.  
  140. #define BLANKS_30 '                              '
  141. #define BLANKS_35 '                                   '
  142. #define BLANKS_40 '                                        '
  143. #define BLANKS_50 '                                                  '
  144. #define BLANKS_60 '                                                            '
  145. #define BLANKS_80 '                                                                                '
  146. #define GENERAL_MGR    16
  147. #define SALES_MGR    4
  148. #define PREVIOUS_FIELD    3
  149. #define ADD_UPDATE    31
  150. \Rogue\Monster\
  151. else
  152.   echo "will not over write ./common.h"
  153. fi
  154. if `test ! -s ./disp_txt.c`
  155. then
  156. echo "writing ./disp_txt.c"
  157. cat > ./disp_txt.c << '\Rogue\Monster\'
  158. /*****************************************************************************
  159. *
  160. * %W%   %G%   %U%
  161. *
  162. *   NAME:           display_txt
  163. *   DESCRIPTION:    Accell/C-hook for displaying a text field
  164. *
  165. *   ACCELL USAGE:   display_txt(target_variable, screen_variable)
  166. *                     where:
  167. *                        target_variable is the long name of
  168. *                                        a UNIFY database field
  169. *                        screen_variable is an ACCELL screen variable
  170. *                                        which MUST be pre-initialized
  171. *                                        to be at least as long as the
  172. *                                        display length of the text field.
  173. *                        
  174. *
  175. *   AUTHOR:         Mark Hargrove
  176. *   DATE:            7/17/87
  177. *
  178. *   Modification History:
  179. *
  180. ******************************************************************************/
  181. #include <chookincl.h>
  182. #define YES 1
  183. #define NO  0
  184.  
  185. int
  186. display_txt(numargs, acclarg)
  187.     int numargs;
  188.     AVAL acclarg[];
  189. {
  190.     char *field_name, *screen_field;
  191.     int rc, field_number, screen_field_width;
  192.     AVAL retval;
  193.  
  194.     /* set up for an error return condition */
  195.     retval.aknd = A_INT; 
  196.     retval.dfflg = YES;
  197.  
  198.     if (numargs != 2)
  199.     {
  200.         retval.aval.inval = 1;
  201.         chookrt(&retval);
  202.         return;
  203.     }
  204.     if (acclarg[0].dfflg == NO || acclarg[1].dfflg == NO)
  205.     {
  206.         retval.aval.inval = 2;
  207.         chookrt(&retval);
  208.         return;
  209.     }
  210.  
  211.     field_name = acclarg[0].aval.stval;
  212.     screen_field = acclarg[1].aval.stval;
  213.  
  214.     if ((field_number = get_fld_num(field_name)) < 0)
  215.     {
  216.         retval.aval.inval = 3;
  217.         chookrt(&retval);
  218.         return;
  219.     }
  220.  
  221.     if ((rc = get_txt_hd(screen_field, field_number)) != 0)
  222.     {
  223.         retval.aval.inval = 4;
  224.         chookrt(&retval);
  225.         return;
  226.     }
  227.     retval.aval.inval = 0;
  228.     chookrt(&retval);
  229.     return;
  230. }
  231. \Rogue\Monster\
  232. else
  233.   echo "will not over write ./disp_txt.c"
  234. fi
  235. if `test ! -s ./edit_txt.c`
  236. then
  237. echo "writing ./edit_txt.c"
  238. cat > ./edit_txt.c << '\Rogue\Monster\'
  239. /*****************************************************************************
  240.  *
  241.  *
  242.  *   NAME:           edit_txt
  243.  *   DESCRIPTION:    Accell/C-hook for editing a text field
  244.  *
  245.  *   ACCELL USAGE:   edit_txt(target_variable)
  246.  *                     where:
  247.  *                        target_variable is the long name of
  248.  *                                        a UNIFY database field
  249.  *
  250.  *   AUTHOR:         Howie Johnson
  251.  *                   ^^^^^^^^^^^^^
  252.  *                   Not the world's prettiest C programmer
  253.  *
  254.  *   DATE:           7/17/87
  255.  * 
  256.  *   NOTES:
  257.  *       0  indicates successful termination - buffer not modified
  258.  *       1  indicates successful termination - buffer modified
  259.  *      -1  unsuccessful termination
  260.  *
  261.  *      the buffer memory for the transfer of data from the database
  262.  *      into a temporary file and vice versa is allocated as size 
  263.  *      TRANS_BUF_SIZE or less.
  264.  *
  265.  *   Modification History:
  266.  *   $Log:    edit_txt.c,v $
  267.  * Revision 1.3  88/01/25  12:54:58  mark
  268.  * .dbv bug workaround code installed by scotth.
  269.  * 
  270.  * Revision 1.2  88/01/20  16:24:03  scotth
  271.  * baseline before code changes to workaround dbv problem
  272.  * 
  273.  *
  274.  *****************************************************************************/
  275.  
  276. #include "fdesc.h"
  277. #include "chookincl.h"
  278. #include "dbtypes.h"
  279. #include "domains.h"
  280. #include <stdio.h>
  281. #include <fcntl.h>
  282. #include <sys/types.h>
  283. #include <sys/stat.h>
  284. #include <termio.h>
  285.  
  286. /* do NOT change the following value unless you know *exactly* what
  287. * you're doing
  288. */
  289. #define TRANS_BUF_SIZE 32752L    /* 32K-16 buffer size */
  290.  
  291. #define YES    1
  292. #define NO     0
  293.  
  294. #ifdef DEBUG
  295. #  define DCLOSE      {if (errlog != NULL) {fclose( errlog); errlog=NULL;}}
  296. #  define DPRINT0(s)      {if (errlog != NULL) fprintf( errlog, s);}
  297. #  define DPRINT1(s,a1)      {if (errlog != NULL) fprintf( errlog, s, a1);}
  298. #  define DPRINT2(s,a1,a2)   {if (errlog != NULL) fprintf( errlog, s, a1, a2);}
  299. #  define DPRINT3(s,a1,a2,a3)   {if (errlog != NULL) fprintf( errlog, s, a1, a2, a3);}
  300. #  define DFLUSH      {if (errlog != NULL) fflush( errlog);}
  301. #else
  302. #  define DCLOSE
  303. #  define DPRINT0(s)
  304. #  define DPRINT1(s,a1)
  305. #  define DPRINT2(s,a1,a2)
  306. #  define DPRINT3(s,a1,a2,a3)
  307. #  define DFLUSH
  308. #endif
  309.  
  310. static char RCS_ID[]="$Header: edit_txt.c,v 1.3 88/01/25 12:54:58 mark Exp $";
  311. static struct termio term_buf, new_termio;
  312. static long dbv_alloc();
  313. static FILE *errlog;
  314. extern int get_fld_num();
  315. extern int errno;
  316. extern int terminate();
  317.  
  318. int   
  319. edit_txt(numargs, acclarg)
  320.    int numargs;
  321.    AVAL acclarg[];
  322. {
  323.    AVAL retval;
  324.    char *field_name;        /* long name of database field */
  325.    int fld;            /* field number */
  326.    long text_size;        /* Actual size of text in DB */
  327.    off_t   file_size;        /* Actual size of edited temp. file */
  328.    long  t_size;        /* Number of bytes to transfer at a whack */
  329.    int   rc;            /* Return code */
  330.    char tname[20];        /* Name of temporary file */
  331.    int fd;            /* File descriptor */
  332.    char *b_ptr;            /* Pointer to transfer buffer */
  333.    long b_size;            /* Size of transfer buffer */
  334.    FIELDLIST flist;        /* Data transfer descriptor block for gfield and pfield */
  335.    FLDESC fdsc;            /* Data base field descriptor */
  336.    struct stat stat_buf;    /* File status block */
  337.    time_t   mod_time;        /* Last modification time of file */
  338.    char errbuf[256];        /* For output messages */
  339.    char cmdbuf[256];        /* Command line buffer for edit command */
  340.    char *editor;        /* Points to EDIT environment variable */
  341.    int pid;            /* process id of child */
  342.    int wait_sts;        /* Status returned by wait() */
  343.    char *Debug;            /* MISBUG environment value */
  344.    extern char *getenv();
  345.  
  346. /*********************************** work around code **********************/
  347.    long orig_size, padded_size;
  348. /***************************************************************************/
  349.  
  350.    /* set up for an error return condition */
  351.    retval.aknd  = A_INT; 
  352.    retval.dfflg = YES;
  353.    Debug = NULL;
  354.    errlog = (FILE *)NULL;
  355.  
  356. #ifdef DEBUG
  357.    if ((Debug = getenv("MISBUG")) != NULL)
  358.    {
  359.       if (*Debug == '\0')
  360.       {
  361.          Debug = NULL;
  362.          errlog = (FILE *)NULL;
  363.       }
  364.       else if ((errlog = fopen("ferrlog", "a+")) == NULL)
  365.       {
  366.          fprintf(stderr, "couldn't open the errlog for append\n");
  367.          return -1;
  368.       }
  369.       fprintf(stderr, "starting debug, value='%s'\n", Debug);
  370.    }
  371.    else
  372.    {
  373.       fprintf(stderr, "no debug this time\n");
  374.    }
  375. #endif
  376.  
  377.    DPRINT0("=============== entering edit_txt ============================\n");
  378.    if (numargs < 1)
  379.    {
  380.       DCLOSE;
  381.       retval.aval.inval = -1;
  382.       chookrt(&retval);
  383.       return;
  384.    }
  385.    if (acclarg[0].dfflg == NO) 
  386.    {
  387.       DCLOSE;
  388.       retval.aval.inval = -2;
  389.       chookrt(&retval);
  390.       return;
  391.    }
  392.  
  393.    field_name = acclarg[0].aval.stval;
  394.  
  395.    if ((fld = get_fld_num(field_name)) < 0)
  396.    {
  397.       DCLOSE;
  398.       retval.aval.inval = -3;
  399.       chookrt(&retval);
  400.       return;
  401.    }
  402.  
  403.    /* Initialization */
  404.    b_ptr = NULL;
  405.    tname[0] = '\0'; 
  406.    fd = -1;
  407.  
  408.    /* Check for valid field type */
  409.    if ((rc = fldesc( fld, &fdsc )) != 1)
  410.    {
  411.       sprintf(errbuf,"edit_txt: got bad field=%d",fld);
  412.       DPRINT1("edit_txt: got bad field=%d\n",fld);
  413.       prtmsg(0,22,errbuf);
  414.       retval.aval.inval = terminate(fd, b_ptr, tname, -1);
  415.       DCLOSE;
  416.       chookrt(&retval);
  417.       return;
  418.    }
  419.  
  420.    if ((rc = fdsc.f_typ) != TEXT )
  421.    {
  422.       sprintf(errbuf,"edit_txt: got non-TEXT field=%d",fld);
  423.       DPRINT1("edit_txt: got non-TEXT field=%d",fld);
  424.       prtmsg(0,22,errbuf);
  425.       retval.aval.inval = terminate(fd, b_ptr, tname, -1);
  426.       DCLOSE;
  427.       chookrt(&retval);
  428.       return;
  429.    }
  430.  
  431.    /* Get size of actual text in database */
  432.    if ((rc = gsize(fld,&text_size)) != 0)
  433.    {
  434.       sprintf(errbuf,"edit_txt: can't retrieve gsize for field=%d",fld);
  435.       DPRINT1("edit_txt: can't retrieve gsize for field=%d",fld);
  436.       prtmsg(0,22,errbuf);
  437.       retval.aval.inval = terminate(fd, b_ptr, tname, -1);
  438.       DCLOSE;
  439.       chookrt(&retval);
  440.       return;
  441.    }
  442.  
  443. /*********************************** work around code **********************/
  444.    /* remember the size of the original text! */
  445.    orig_size = text_size;
  446.    DPRINT1("edit_txt: original size=%d\n", orig_size);
  447. /***************************************************************************/
  448.  
  449.    /* Open a temporary file */
  450.    strcpy(tname,"edtdbXXXXXX");
  451.    mktemp(tname);
  452.    if ((fd=open(tname, O_RDWR | O_CREAT | O_TRUNC, 0666 )) < 0)
  453.    {
  454.       sprintf(errbuf,"edit_txt: can't open temp. file=%s",tname);
  455.       DPRINT1("edit_txt: can't open temp. file=%s",tname);
  456.       prtmsg(0,22,errbuf);
  457.       retval.aval.inval = terminate(-1,b_ptr,"",-1);
  458.       DCLOSE;
  459.       chookrt(&retval);
  460.       return;
  461.    }
  462.  
  463.    /* Open buffer for transfer of data from database to temp file */
  464.    b_size = (text_size > TRANS_BUF_SIZE) ? TRANS_BUF_SIZE : text_size;
  465.    DPRINT1("edit_txt: malloc'ed size = %d\n", b_size);
  466.    if ((b_ptr = (char *)malloc((unsigned)b_size)) == NULL)
  467.    {
  468.       sprintf(errbuf,"edit_txt: can't malloc buffer for data transfer");
  469.       DPRINT0("edit_txt: can't malloc buffer for data transfer");
  470.       prtmsg(0,22,errbuf);
  471.       retval.aval.inval = terminate(fd, b_ptr, tname, -1);
  472.       DCLOSE;
  473.       chookrt(&retval);
  474.       return;
  475.    }
  476.  
  477.    /* Transfer data from database to temporary file */
  478.    flist.fnum = fld;
  479.    flist.fdata = b_ptr;
  480.    flist.mode = FL_TRUNC;
  481.    flist.start = 0L;
  482.    while(text_size > 0L)
  483.    {
  484.       t_size = (text_size > b_size) ? b_size : text_size;
  485.       flist.size = t_size;
  486.       DPRINT3("edit_txt: flist.fnum=%d, flist.start=%d, flist.size=%d\n",
  487.                          flist.fnum, flist.start, flist.size);
  488.       if ((rc = gfield(fld, (char *)0, &flist)) != 0)
  489.       {
  490.          sprintf(errbuf,"edit_txt: gfield error=%d",rc); 
  491.          DPRINT1("\tedit_txt: gfield error=%d",rc); 
  492.          prtmsg(0,22,errbuf);
  493.          retval.aval.inval = terminate(fd, b_ptr, tname, -1);
  494.          DCLOSE;
  495.          chookrt(&retval);
  496.          return;
  497.       }
  498.  
  499.       if ((rc = write(fd, b_ptr, (unsigned)t_size)) != t_size)
  500.       {
  501.          sprintf(errbuf,"edit_txt: write error on file=%s",tname);  
  502.          DPRINT1("edit_txt: write error on file=%s",tname);  
  503.          prtmsg(0,22,errbuf);
  504.          retval.aval.inval = terminate(fd, b_ptr, tname, -1);
  505.          DCLOSE;
  506.          chookrt(&retval);
  507.          return;
  508.       }
  509.       flist.start += t_size;
  510.       text_size -= t_size;
  511.    }
  512.  
  513.    /* Free previously allocated buffer */
  514.    free(b_ptr);
  515.    b_ptr = NULL;
  516.  
  517.    /* Note the file modification time */
  518.    if ((rc = fstat(fd, &stat_buf)) != 0)
  519.    {
  520.       sprintf(errbuf,"edit_txt: can't fstat file=%s",tname);
  521.       DPRINT1("edit_txt: can't fstat file=%s",tname);
  522.       prtmsg(0,22,errbuf);
  523.       retval.aval.inval = terminate(fd, b_ptr, tname, -1);
  524.       DCLOSE;
  525.       chookrt(&retval);
  526.       return;
  527.    }
  528.    mod_time = stat_buf.st_mtime;
  529.  
  530.    /* Check for EDIT environment variable */
  531.    if ((editor = (char *)getenv("EDIT")) == NULL)
  532.    {
  533.       editor = "/usr/bin/vedit";
  534.       sprintf(errbuf,"EDIT environment variable is not set, using vedit");
  535.       prtmsg(0,22,errbuf);
  536.    }
  537.  
  538.  
  539.    /* save stty settings */
  540.    ioctl(0,TCGETA, &term_buf);
  541.  
  542.    DPRINT0( "TTY Settings:\n");
  543.    DPRINT1( "c_cflag:   %o\n", term_buf.c_cflag);
  544.    DPRINT1( "c_iflag:   %o\n", term_buf.c_iflag);
  545.    DPRINT1( "c_oflag:   %o\n", term_buf.c_oflag);
  546.    DPRINT1( "c_lflag:   %o\n", term_buf.c_lflag);
  547.    DFLUSH;
  548.  
  549.    /* Establish new termio values for raw input mode */
  550.    new_termio = term_buf;
  551.    new_termio.c_iflag = IGNBRK;
  552.    new_termio.c_lflag = 0;
  553.    new_termio.c_cc[VMIN]  = 1;
  554.    new_termio.c_cc[VTIME] = 0;
  555.  
  556.    /* set the new values */
  557.    ioctl(0,TCSETA, &new_termio);
  558.  
  559.    /* Invoke the editor */
  560.    if ((pid = fork()) == 0)
  561.    {
  562.       if (execlp(editor, editor, tname, NULL) == -1)
  563.       {
  564.          sprintf(errbuf, "can't exec %s, %s", editor, tname);
  565.          DPRINT2( "can't exec %s, %s", editor, tname);
  566.          prtmsg(0,22,errbuf);
  567.          DCLOSE;
  568.          exit(-1);
  569.       }
  570.    }
  571.    else
  572.    {
  573.  
  574.       DPRINT1( "waiting for pid %d\n", pid);
  575.       DFLUSH;
  576.       while((rc=wait(&wait_sts)) != pid )
  577.       {
  578.  
  579.          DPRINT3( "! wait returned BAD pid %d, status %d, errno %d\n", rc, wait_sts,errno);
  580.          DFLUSH;
  581.          if( rc == -1 )
  582.          {
  583.             DPRINT1( "! killing process no. %d\n",pid);
  584.             DFLUSH;
  585.             rc=kill(pid,9);
  586.             DPRINT2( "kill return code=%d, errno=%d\n",rc,errno);
  587.             DFLUSH;
  588.             break;
  589.          }
  590.       }
  591.  
  592.       DPRINT2( "  wait returned OK pid %d, status %d\n", rc, wait_sts);
  593.       DFLUSH;
  594.  
  595.    }
  596.    /* restore stty settings */
  597.    ioctl( 0, TCSETA, &term_buf);
  598.  
  599.    DPRINT0("edit_txt: after edit\n");
  600.    /* Write file to database if necessary */
  601.    if ((rc = fstat(fd, &stat_buf)) != 0)
  602.    {
  603.       sprintf(errbuf,"edit_txt: can't fstat file=%s",tname);
  604.       DPRINT1("edit_txt: can't fstat file=%s",tname);
  605.       prtmsg(0,22,errbuf);
  606.       retval.aval.inval = terminate(fd, b_ptr, tname, -1);
  607.       DCLOSE;
  608.       chookrt(&retval);
  609.       return;
  610.    }
  611.  
  612.    if (stat_buf.st_mtime != mod_time) /* then buffer was modified */
  613.    {
  614.       /* Open buffer for transfer of data from database to temp. file */
  615.       file_size = stat_buf.st_size;
  616.  
  617. /*********************************** work around code **********************/
  618.       DPRINT1("edit_txt: file_size=%d\n", file_size);
  619.       padded_size = dbv_alloc((long)file_size);
  620.       b_size = (padded_size > TRANS_BUF_SIZE) ? TRANS_BUF_SIZE : padded_size;
  621.       DPRINT2("edit_txt: padded_size=%d, b_size=%d\n", padded_size, b_size);
  622. /***************************************************************************/
  623.  
  624.       if ((b_ptr = (char *)malloc((unsigned)b_size)) == NULL)
  625.       {
  626.          sprintf(errbuf,"edit_txt: can't retrieve gsize for field=%d",fld);
  627.          DPRINT1("edit_txt: can't retrieve gsize for field=%d",fld);
  628.          prtmsg(0,22,errbuf);
  629.          retval.aval.inval = terminate(fd, b_ptr, tname, -1);
  630.          DCLOSE;
  631.          chookrt(&retval);
  632.          return;
  633.       }
  634.    
  635.       /* Transfer data from database to temp. file */
  636.       flist.fnum = fld;
  637.       flist.fdata = b_ptr;
  638.       flist.mode = FL_TRUNC;
  639.       flist.start = 0L;
  640.       (void) lseek(fd,0L,0);   /* Rewind the temp file */
  641.  
  642. /*********************** work around code modifications **********************/
  643.  
  644.       while(file_size > 0)
  645.       {
  646.          t_size = ((file_size > b_size) ? b_size : file_size);
  647.          flist.size = ((padded_size > b_size) ? b_size : padded_size);
  648.          DPRINT3("\tedit_txt: flist.start=%d, flist.size=%d, t_size=%d\n",
  649.                   flist.start, flist.size, t_size);
  650.          (void)memset( b_ptr, '\0', b_size);
  651.          if ((rc=read(fd, b_ptr, (unsigned)t_size)) != t_size)
  652.          {
  653.             DPRINT1("edit_txt: read error, rc=%d\n", rc);
  654.             sprintf(errbuf, "edit_txt: error reading file, rc=%d", rc);
  655.             prtmsg(0,22,errbuf);
  656.             retval.aval.inval = terminate(fd, b_ptr, tname, -1);
  657.             chookrt(&retval);
  658.             return;
  659.          }
  660.  
  661.          if ((rc=pfield(fld,(char *)0,&flist)) != 0)
  662.          {
  663.             sprintf(errbuf,"edit_txt: pfield error=%d",rc); 
  664.             prtmsg(0,22,errbuf);
  665.             retval.aval.inval = terminate(fd, b_ptr, tname, -1);
  666.             DCLOSE;
  667.             chookrt(&retval);
  668.             return;
  669.          }
  670.          flist.start += t_size;
  671.          file_size   -= t_size;
  672.          padded_size -= t_size;
  673.       }
  674.  
  675. /************************************************************************/
  676.  
  677.       retval.aval.inval = terminate(fd, b_ptr, tname, 1);
  678.       chookrt(&retval);
  679.    } /* End if (stat_buf . . . */
  680.    else /* buffer was NOT modified */
  681.    {
  682.       retval.aval.inval = terminate(fd, b_ptr, tname, 0);
  683.       chookrt(&retval);
  684.    }
  685.    DCLOSE;
  686.    return;
  687. }
  688.  
  689. /* Clean up all open files, buffers, and remove temp. file from directory */
  690. int
  691. terminate(fd, b_ptr, file_name, val)
  692.    int fd;      /* File descriptor */
  693.    char *b_ptr;      /* Buffer area */
  694.    char *file_name;   /* Pointer to file name */
  695.    int  val;      /* Value to return */
  696. {
  697.    if (fd >= 0)
  698.    {
  699.       close(fd);
  700.    }   
  701.  
  702.    if (b_ptr != NULL)
  703.    {
  704.       free(b_ptr);
  705.    }
  706.  
  707.    if (*file_name != '\0')
  708.    {
  709.       unlink(file_name);
  710.    }
  711.    return(val);
  712. }
  713.  
  714. /****************************************************************/
  715.  
  716. struct allocsize {
  717.    long  boundary;    /* break point for allocation changes    */
  718.    long  increment;    /* allocation increment below this boundary    */
  719. };
  720. static struct allocsize btab[] = {
  721.       { 32768L-16L, 32L },
  722.       { (1024L*1024L)-16L, 32768L },
  723.       { (1024L*1024L*1024L)-16L, (1024L*1024L) }
  724.    };
  725. #define BTABSIZ (sizeof(btab) / sizeof(btab[0]))
  726.  
  727. static long
  728. dbv_alloc(insize)
  729.    long insize;
  730. {
  731.    register int i;
  732.    register long retval;
  733.  
  734.    for (i=0; i < BTABSIZ; ++i)
  735.    {
  736.       if (insize <= btab[i].boundary)
  737.       {
  738.          break;
  739.       }
  740.    }
  741.    retval =  ((insize / btab[i].increment) + 1) * btab[i].increment - 16L;
  742.    if (retval < insize)
  743.    {
  744.       retval += btab[i].increment;
  745.    }
  746.    return retval;
  747. }
  748. \Rogue\Monster\
  749. else
  750.   echo "will not over write ./edit_txt.c"
  751. fi
  752. if `test ! -s ./extern.h`
  753. then
  754. echo "writing ./extern.h"
  755. cat > ./extern.h << '\Rogue\Monster\'
  756. /* external C-Hook declarations */ 
  757.  
  758. EXTERN C NUMERIC FUNCTION display_txt($x1, RESULT $x2)
  759. EXTERN C NUMERIC FUNCTION edit_txt($x1)
  760. EXTERN C NUMERIC FUNCTION show_txt($x1)
  761. EXTERN C NUMERIC FUNCTION to_upper($x1, RESULT $x2)
  762. EXTERN C NUMERIC FUNCTION text_size($x1)
  763. EXTERN C NUMERIC FUNCTION week_day()
  764. EXTERN C NUMERIC FUNCTION day_of_week($x1)
  765. \Rogue\Monster\
  766. else
  767.   echo "will not over write ./extern.h"
  768. fi
  769. if `test ! -s ./get_fld_no.c`
  770. then
  771. echo "writing ./get_fld_no.c"
  772. cat > ./get_fld_no.c << '\Rogue\Monster\'
  773. #include <stdio.h>
  774. /*
  775. get_fld_num()   --  gets field number from short field name (or long name)
  776.  
  777. USAGE:
  778.     int      field         
  779.     char *string_ptr    Points to name of desired field 
  780.  
  781.     field = get_fld_num( string_ptr );
  782.  
  783. NOTES:
  784.     returns zero if name not recognized 
  785. */
  786. char *fldname();
  787. char *fldsyn();
  788.  
  789. /*-------------------------------------------------------------*/
  790. int     get_fld_num( s_ptr )
  791. char *s_ptr;
  792. {
  793. int  max_field;    /* Highest field index in use in system */
  794. int  fld;            /* Counter */
  795. char *t_ptr;         /* temp. string pointer */
  796.     
  797.     /*----------------------------------------------------------*/
  798.     /* Find out how many fields are in the database */
  799.     max_field = numflds();
  800.     
  801.     /*----------------------------------------------------------*/
  802.     /* Try all short database names looking for a match */
  803.     for (fld=1; fld<=max_field; fld++ )
  804.     {
  805.         if ( (t_ptr=fldsyn(fld)) != NULL )
  806.         {
  807.             if ( strcmp( s_ptr, t_ptr ) == 0 )    
  808.             {
  809.                 return( fld );
  810.             }
  811.         }
  812.         
  813.     }
  814.  
  815.     /*----------------------------------------------------------*/
  816.     /* Try all long database names looking for a match */
  817.     for (fld=1; fld<=max_field; fld++ )
  818.     {
  819.         if ( (t_ptr=fldname(fld)) != NULL )
  820.         {
  821.             if ( strcmp( s_ptr, t_ptr ) == 0 )    
  822.             {
  823.                 return( fld );
  824.             }
  825.         }
  826.         
  827.     }
  828.  
  829.     /*----------------------------------------------------------*/
  830.     /* Field name not recognized */
  831.     return( -1 );
  832. }
  833. \Rogue\Monster\
  834. else
  835.   echo "will not over write ./get_fld_no.c"
  836. fi
  837. if `test ! -s ./show_txt.c`
  838. then
  839. echo "writing ./show_txt.c"
  840. cat > ./show_txt.c << '\Rogue\Monster\'
  841. /*****************************************************************************
  842. *
  843. * %W%   %G%   %U%
  844. *
  845. *   NAME:           show_txt
  846. *   DESCRIPTION:    Accell/C-hook for displaying a text field
  847. *
  848. *   ACCELL USAGE:   show_txt(target_variable)
  849. *                     where:
  850. *                        target_variable is the long name of
  851. *                                        a UNIFY database field
  852. *
  853. *   AUTHOR:         Mark Hargrove (based on code in edit_txt)
  854. *   DATE:           8/6/87
  855. *
  856. *   RETURNS:
  857. *            0 - successful termination
  858. *         -1 - unsuccessful termintation
  859. *
  860. *      the buffer memory for the transfer of data from the database
  861. *      into a temporary file and vice versa is allocated as size 
  862. *      TRANS_BUF_SIZE or less.
  863. *
  864. *   Modification History:
  865. *
  866. ******************************************************************************/
  867. #include "fdesc.h"
  868. #include "chookincl.h"
  869. #include "dbtypes.h"
  870. #include "domains.h"
  871. #include <stdio.h>
  872. #include <fcntl.h>
  873. #include <sys/types.h>
  874. #include <sys/stat.h>
  875.  
  876. #define TRANS_BUF_SIZE 8192L
  877. #define YES   1
  878. #define NO   0
  879.  
  880. extern int get_fld_num();
  881.  
  882. int   
  883. show_txt(numargs, acclarg)
  884.    int numargs;
  885.    AVAL acclarg[];
  886. {
  887.    AVAL retval;
  888.    char *field_name;  /* long name of database field */
  889.    int fld;            /* field number */
  890.    long text_size;   /* Actual size of text in DB */
  891.    off_t   file_size;    /* Actual size of edited temp. file */
  892.    long  t_size;      /* Number of bytes to transfer at a whack */
  893.    int   rc;         /* Return code */
  894.    char tname[20];   /* Name of temporary file */
  895.    int fd;            /* File descriptor */
  896.    char *b_ptr;      /* Pointer to transfer buffer */
  897.    long b_size;      /* Size of transfer buffer */
  898.    FIELDLIST flist;   /* Data transfer descriptor block for gfield and pfield */
  899.    FLDESC fdsc;      /* Data base field descriptor */
  900.    struct stat stat_buf; /* File status block */
  901.    time_t   mod_time; /* Last modification time of file */
  902.    char errbuf[256];  /* For output messages */
  903.    char cmdbuf[256];  /* Command line buffer for edit command */
  904.    char *editor;      /* Points to EDIT environment variable */
  905.    int pid;             /* process id of child */
  906.  
  907.  
  908.    /* set up for an error return condition */
  909.    retval.aknd = A_INT; 
  910.    retval.dfflg = YES;
  911.  
  912.    if (numargs != 1)
  913.    {
  914.       retval.aval.inval = -1;
  915.       chookrt(&retval);
  916.       return;
  917.    }
  918.    if (acclarg[0].dfflg == NO)
  919.    {
  920.       retval.aval.inval = -2;
  921.       chookrt(&retval);
  922.       return;
  923.    }
  924.  
  925.    field_name = acclarg[0].aval.stval;
  926.  
  927.    if ((fld = get_fld_num(field_name)) < 0)
  928.    {
  929.       retval.aval.inval = -3;
  930.       chookrt(&retval);
  931.       return;
  932.    }
  933.  
  934.    /* Initialization */
  935.    b_ptr = NULL;
  936.    tname[0] = '\0'; 
  937.    fd = -1;
  938.  
  939.    /* Check for valid field type */
  940.    if ((rc = fldesc( fld, &fdsc )) != 1)
  941.    {
  942.       sprintf(errbuf,"edit_txt: got bad field=%d",fld);
  943.       prtmsg(0,22,errbuf);
  944.       retval.aval.inval = terminate(fd, b_ptr, tname, -1);
  945.       chookrt(&retval);
  946.       return;
  947.    }
  948.  
  949.    if ((rc = fdsc.f_typ) != TEXT )
  950.    {
  951.       sprintf(errbuf,"edit_txt: got non-TEXT field=%d",fld);
  952.       prtmsg(0,22,errbuf);
  953.       retval.aval.inval = terminate(fd, b_ptr, tname, -1);
  954.       chookrt(&retval);
  955.       return;
  956.    }
  957.  
  958.    /* Get size of actual text in database */
  959.    if ((rc = gsize(fld,&text_size)) != 0)
  960.    {
  961.       sprintf(errbuf,"edit_txt: can't retrieve gsize for field=%d",fld);
  962.       prtmsg(0,22,errbuf);
  963.       retval.aval.inval = terminate(fd, b_ptr, tname, -1);
  964.       chookrt(&retval);
  965.       return;
  966.    }
  967.    
  968.    /* Open a temporary file */
  969.    strcpy(tname,"edtdbXXXXXX");
  970.    mktemp(tname);
  971.    if ((fd=open(tname, O_RDWR | O_CREAT | O_TRUNC, 0666 )) < 0)
  972.    {
  973.       sprintf(errbuf,"edit_txt: can't open temp. file=%s",tname);
  974.       prtmsg(0,22,errbuf);
  975.       retval.aval.inval = terminate(-1,b_ptr,"",-1);
  976.       chookrt(&retval);
  977.       return;
  978.    }
  979.  
  980.    /* Open buffer for transfer of data from database to temp file */
  981.    b_size = (text_size > TRANS_BUF_SIZE) ? TRANS_BUF_SIZE : text_size;
  982.    if ((b_ptr = (char *)malloc((unsigned)b_size)) == NULL)
  983.    {
  984.       sprintf(errbuf,"edit_txt: can't retrieve gsize for field=%d",fld);
  985.       prtmsg(0,22,errbuf);
  986.       retval.aval.inval = terminate(fd, b_ptr, tname, -1);
  987.       chookrt(&retval);
  988.       return;
  989.    }
  990.  
  991.    /* Transfer data from database to temporary file */
  992.    flist.fnum = fld;
  993.    flist.fdata = b_ptr;
  994.    flist.mode = FL_TRUNC;
  995.    flist.start = (long)0;
  996.    while(text_size > 0)
  997.    {
  998.       t_size = (text_size > b_size) ? b_size : text_size;
  999.       flist.size = t_size;
  1000.       if ((rc = gfield(fld,(char *)0,&flist)) != 0)
  1001.       {
  1002.          sprintf(errbuf,"edit_txt: gfield error=%d",rc); 
  1003.          prtmsg(0,22,errbuf);
  1004.          retval.aval.inval = terminate(fd, b_ptr, tname, -1);
  1005.          chookrt(&retval);
  1006.          return;
  1007.       }
  1008.  
  1009.       if ((rc = write(fd, b_ptr, (unsigned)t_size)) != t_size)
  1010.       {
  1011.          sprintf(errbuf,"edit_txt: write error on file=%s",tname);  
  1012.          prtmsg(0,22,errbuf);
  1013.          retval.aval.inval = terminate(fd, b_ptr, tname, -1);
  1014.          chookrt(&retval);
  1015.          return;
  1016.       }
  1017.       flist.start += t_size;
  1018.       text_size -= t_size;
  1019.    }
  1020.  
  1021.    /* Free previously allocated buffer */
  1022.    free(b_ptr);
  1023.    b_ptr = NULL;
  1024.  
  1025.    /* Note the file modification time */
  1026.    if ((rc = fstat(fd, &stat_buf)) != 0)
  1027.    {
  1028.       sprintf(errbuf,"edit_txt: can't fstat file=%s",tname);
  1029.       prtmsg(0,22,errbuf);
  1030.       retval.aval.inval = terminate(fd, b_ptr, tname, -1);
  1031.       chookrt(&retval);
  1032.       return;
  1033.    }
  1034.    mod_time = stat_buf.st_mtime;
  1035.  
  1036.    /* Check for EDIT environment variable */
  1037.    if ((editor = (char *)getenv("EDIT")) == NULL)
  1038.    {
  1039.       editor = "/usr/bin/vedit";
  1040.       sprintf(errbuf,"EDIT environment variable is not set, using vedit editor");
  1041.       prtmsg(0,22,errbuf);
  1042.    }
  1043.  
  1044.    /* Invoke the editor */
  1045.    /* setcook();   */
  1046.     /*
  1047.    strcpy(cmdbuf, editor);
  1048.    strcat(cmdbuf, " ");
  1049.    strcat(cmdbuf, tname);
  1050.    system(cmdbuf);
  1051.     */
  1052.  
  1053.    if ((pid = fork()) == 0)
  1054.    {
  1055.       if (execlp(editor, editor, tname, NULL) == -1)
  1056.       {
  1057.          sprintf(errbuf, "can't exec %s, %s", editor, tname);
  1058.          prtmsg(0,22,errbuf);
  1059.          exit(-1);
  1060.       }
  1061.    }
  1062.    else
  1063.    {
  1064.       wait(NULL);
  1065.    }
  1066.    setraw();
  1067.     retval.aval.inval = terminate(fd, b_ptr, tname, 0);
  1068.     chookrt(&retval);
  1069.     return;
  1070. }
  1071. \Rogue\Monster\
  1072. else
  1073.   echo "will not over write ./show_txt.c"
  1074. fi
  1075. if `test ! -s ./text_size.c`
  1076. then
  1077. echo "writing ./text_size.c"
  1078. cat > ./text_size.c << '\Rogue\Monster\'
  1079. /*****************************************************************************
  1080. *
  1081. * %W%   %G%   %U%
  1082. *
  1083. *   NAME:           text_size
  1084. *   DESCRIPTION:    Accell/C-hook for determining actual size of a text field
  1085. *
  1086. *   ACCELL USAGE:   text_size(target_variable)
  1087. *                     where:
  1088. *                        target_variable is the long name of
  1089. *                                        a UNIFY database field
  1090. *
  1091. *   AUTHOR:         Mark Hargrove
  1092. *   DATE:           8/25/87
  1093. *
  1094. *   RETURNS:
  1095. *         size of text on successul return
  1096. *      < 0 on error return
  1097. *
  1098. ******************************************************************************/
  1099. #include "fdesc.h"
  1100. #include "chookincl.h"
  1101. #include "dbtypes.h"
  1102. #include "domains.h"
  1103. #include <stdio.h>
  1104. #include <fcntl.h>
  1105. #include <sys/types.h>
  1106. #include <sys/stat.h>
  1107.  
  1108. #define YES   1
  1109. #define NO   0
  1110.  
  1111. extern int get_fld_num();
  1112.  
  1113. int   
  1114. text_size(numargs, acclarg)
  1115.    int numargs;
  1116.    AVAL acclarg[];
  1117. {
  1118.    AVAL retval;
  1119.    char *field_name;  /* long name of database field */
  1120.    int fld;            /* field number */
  1121.    long txt_size;   /* Actual size of text in DB */
  1122.    int   rc;         /* Return code */
  1123.    FIELDLIST flist;   /* Data transfer descriptor block for gfield and pfield */
  1124.    FLDESC fdsc;      /* Data base field descriptor */
  1125.    char errbuf[256];  /* For output messages */
  1126.  
  1127.    /* set up for an error return condition */
  1128.    retval.aknd = A_INT; 
  1129.    retval.dfflg = YES;
  1130.  
  1131.    if (numargs != 1)
  1132.    {
  1133.       retval.aval.inval = -1;
  1134.       chookrt(&retval);
  1135.       return;
  1136.    }
  1137.    if (acclarg[0].dfflg == NO)
  1138.    {
  1139.       retval.aval.inval = -2;
  1140.       chookrt(&retval);
  1141.       return;
  1142.    }
  1143.  
  1144.    field_name = acclarg[0].aval.stval;
  1145.  
  1146.    if ((fld = get_fld_num(field_name)) < 0)
  1147.    {
  1148.       retval.aval.inval = -3;
  1149.       chookrt(&retval);
  1150.       return;
  1151.    }
  1152.  
  1153.    /* Check for valid field type */
  1154.    if ((rc = fldesc( fld, &fdsc )) != 1)
  1155.    {
  1156.       sprintf(errbuf,"txt_size: got bad field=%d",fld);
  1157.       prtmsg(0,22,errbuf);
  1158.       retval.aval.inval = -4;
  1159.       chookrt(&retval);
  1160.       return;
  1161.    }
  1162.  
  1163.    if ((rc = fdsc.f_typ) != TEXT )
  1164.    {
  1165.       sprintf(errbuf,"txt_size: got non-TEXT field=%d",fld);
  1166.       prtmsg(0,22,errbuf);
  1167.       retval.aval.inval = -5;
  1168.       chookrt(&retval);
  1169.       return;
  1170.    }
  1171.  
  1172.    /* Get size of actual text in database */
  1173.    if ((rc = gsize(fld, &txt_size)) != 0)
  1174.    {
  1175.       sprintf(errbuf,"text_size: can't retrieve gsize for field=%d",fld);
  1176.       prtmsg(0,22,errbuf);
  1177.       retval.aval.inval = -6;
  1178.       chookrt(&retval);
  1179.       return;
  1180.    }
  1181.     retval.aval.inval = txt_size;
  1182.     chookrt(&retval);
  1183.     return;
  1184. }
  1185. \Rogue\Monster\
  1186. else
  1187.   echo "will not over write ./text_size.c"
  1188. fi
  1189. if `test ! -s ./to_upper.c`
  1190. then
  1191. echo "writing ./to_upper.c"
  1192. cat > ./to_upper.c << '\Rogue\Monster\'
  1193. /*****************************************************************************
  1194. *
  1195. * %W%   %G%   %U%
  1196. *
  1197. *   NAME:           to_upper
  1198. *   DESCRIPTION:    Accell/C-hook for converting a string to all upper case
  1199. *
  1200. *   ACCELL USAGE:   to_upper(string)
  1201. *                     where:
  1202. *                        string             is a string value
  1203. *
  1204. *   AUTHOR:         Mark Hargrove
  1205. *   DATE:            7/30/87
  1206. *
  1207. *   Modification History:
  1208. *
  1209. ******************************************************************************/
  1210. #include <chookincl.h>
  1211. #define YES 1
  1212. #define NO  0
  1213.  
  1214. int
  1215. to_upper(numargs, acclarg)
  1216.     int numargs;
  1217.     AVAL acclarg[];
  1218. {
  1219.     AVAL retval;
  1220.     register int i;
  1221.  
  1222.     /* set up for an error return condition */
  1223.     retval.aknd = A_INT; 
  1224.     retval.dfflg = YES;
  1225.  
  1226.     if (numargs != 2)
  1227.     {
  1228.         retval.aval.inval = 1;
  1229.         chookrt(&retval);
  1230.         return;
  1231.     }
  1232.     if (acclarg[0].dfflg == NO || acclarg[1].dfflg == NO)
  1233.     {
  1234.         retval.aval.inval = 2;
  1235.         chookrt(&retval);
  1236.         return;
  1237.     }
  1238.     if (acclarg[0].aknd != A_STR || acclarg[1].aknd != A_STR)
  1239.     {
  1240.         retval.aval.inval = 3;
  1241.         chookrt(&retval);
  1242.         return;
  1243.     }
  1244.     if (strlen(acclarg[0].aval.stval) > strlen(acclarg[1].aval.stval))
  1245.     {
  1246.         retval.aval.inval = 4;
  1247.         chookrt(&retval);
  1248.         return;
  1249.     }
  1250.     cfill('\0', acclarg[1].aval.stval, strlen(acclarg[1].aval.stval));
  1251.     for (i = 0; i < strlen(acclarg[0].aval.stval); i++)
  1252.         acclarg[1].aval.stval[i] = toupper(acclarg[0].aval.stval[i]);
  1253.         
  1254.     retval.aval.inval = 0;
  1255.     chookrt(&retval);
  1256.     return;
  1257. }
  1258. \Rogue\Monster\
  1259. else
  1260.   echo "will not over write ./to_upper.c"
  1261. fi
  1262. if `test ! -s ./week_day.c`
  1263. then
  1264. echo "writing ./week_day.c"
  1265. cat > ./week_day.c << '\Rogue\Monster\'
  1266. /******************************************************************************
  1267. *  PROGRAM    :  week_day
  1268. *  DESCRIPTION:  returns the day of the week given the current date
  1269. *
  1270. *  AUTHOR     :  Scott Henry    
  1271. *  DATE       :  11/18/87  
  1272. ******************************************************************************/
  1273. #include <time.h>
  1274. #include <stdio.h>
  1275. #include <chookincl.h>
  1276. #define YES 1
  1277. #define NO  0
  1278. extern int errno;
  1279. static char *RCSid = "$Header: week_day.c,v 1.2 88/01/20 16:29:47 root Exp $";
  1280.  
  1281. int
  1282. week_day(numargs, acclarg)        /* returns 0 = Sunday, 6 = Saturday */
  1283.     int numargs;
  1284.     AVAL acclarg[];
  1285. {
  1286.     AVAL    retval;
  1287.     long    clock, time();
  1288.     struct    tm *timex;
  1289.  
  1290.     /* set up for an error return */
  1291.     retval.aknd  = A_INT;
  1292.     retval.dfflg = YES;
  1293.     retval.aval.inval = 0;
  1294.  
  1295.     if (numargs == 0)
  1296.     {                /* day-of-week based on system clock */
  1297.         clock = time((long *)0);
  1298.         timex = localtime(&clock);
  1299.         retval.aval.inval = timex->tm_wday;
  1300.     }
  1301.     chookrt(&retval);
  1302.     return;
  1303. }
  1304.  
  1305. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
  1306.  
  1307. int
  1308. day_of_week( numarg, acclarg)
  1309.    int numarg;
  1310.    AVAL acclarg[];
  1311. {
  1312.     AVAL    retval;
  1313.     long    udate;
  1314.  
  1315.     /* set up for an error return */
  1316.     retval.aknd  = A_INT;
  1317.     retval.dfflg = YES;
  1318.     retval.aval.inval = 0;
  1319.  
  1320.     if (numarg == 1 && acclarg[0].dfflg == YES && acclarg[0].aknd == A_DATE)
  1321.     {                /* day-of-week based on input date */
  1322.         udate = acclarg[0].aval.daval;
  1323.         retval.aval.inval = (udate + 32764L) % 7;
  1324.     }
  1325.  
  1326.     chookrt(&retval);
  1327.     return;
  1328. }
  1329.  
  1330. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1331. $Log:    week_day.c,v $
  1332.  * Revision 1.2  88/01/20  16:29:47  root
  1333.  * baseline before code changes to workaround .dbv bug
  1334.  * 
  1335.  * Revision 1.1  87/11/18  12:19:31  scotth
  1336.  * Initial revision
  1337.  * 
  1338. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
  1339. \Rogue\Monster\
  1340. else
  1341.   echo "will not over write ./week_day.c"
  1342. fi
  1343. if `test ! -s ./fedit.fs`
  1344. then
  1345. echo "writing ./fedit.fs"
  1346. cat > ./fedit.fs << '\Rogue\Monster\'
  1347. /******************************************************************************
  1348. *  $Header: fedit.fs,v 2.1 88/01/13 09:30:36 scotth Exp $
  1349. *
  1350. *  FORM       :  fedit
  1351. *  DESCRIPTION:  text editor interface for Accell using c-hooks
  1352. *                in the customized AMGR
  1353. *
  1354. *  AUTHOR     :  Mark Hargrove  
  1355. *  DATE       :  11/11/87  
  1356. *
  1357. ******************************************************************************/
  1358. #include "extern.h"
  1359.  
  1360. FORM fedit
  1361.  
  1362. #include "common.h"
  1363.  
  1364. /*****************************  FIELD SECTION ********************************/
  1365.  
  1366. FIELD s_text
  1367.  
  1368.     BEFORE FIELD
  1369.         display 'Loading Editor...' for fyi_message
  1370.         set $rc to edit_txt($glob_text_field)
  1371.         repaint screen
  1372.         if $rc < 0 then 
  1373.         begin
  1374.             display 'edit_txt returned error: ' + val_to_str$($rc) for fyi_message wait
  1375.         end
  1376.         next action is previous form
  1377.  
  1378. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1379. $Log:    fedit.fs,v $
  1380. Revision 2.1  88/01/13  09:30:36  scotth
  1381. Frozen for 1.0 Release
  1382.  
  1383. Revision 2.0  87/12/18  12:04:00  scotth
  1384. first release
  1385.  
  1386. Revision 1.7  87/11/25  08:45:52  scotth
  1387. Alpha-1 release
  1388.  
  1389. Revision 1.5  87/11/23  14:08:25  scotth
  1390. frozen for Alpha test
  1391.  
  1392. Revision 1.1  87/11/11  16:14:50  scotth
  1393. mostly working state
  1394.  
  1395. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
  1396. \Rogue\Monster\
  1397. else
  1398.   echo "will not over write ./fedit.fs"
  1399. fi
  1400. if `test ! -s ./fedit.fq.uue`
  1401. then
  1402. echo "writing ./fedit.fq.uue"
  1403. cat > ./fedit.fq.uue << '\Rogue\Monster\'
  1404.  
  1405. begin 664 fedit.fq
  1406. M4U$``0`$```!20```&X``69E9&ET````````````````````````````````N
  1407. M`````````````````````````````````````````````````````````````
  1408. M``````````````````````````````#R```!<P``````````````````````F
  1409. M`````````````````````````````````````````````````````````````
  1410. M````````````````````````````````````````````%@`'``$````!````?
  1411. M```!````````````````````"``=``8`$@`````````/``IF961I="YH;'``5
  1412. M`````0````````````````````````$!`0$!`0$!```!`````'-?=&5X=```A
  1413. M```````````!`)@``0`"````````!`!F`PP```,!```````````/<U]I;7!EE
  1414. M;F1I;E]H;'``````%@T@(%!L96%S90T@(%=A:70N+BX-#0``````````````/
  1415. B`````````````````````````````````````````````````
  1416. ``
  1417. end
  1418. size 439
  1419. \Rogue\Monster\
  1420. else
  1421.   echo "will not over write ./fedit.fq.uue"
  1422. fi
  1423. echo "Finished archive 5 of 5"
  1424. exit
  1425.  
  1426.  
  1427. -- 
  1428. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1429. Mark A. Hargrove                                             U.S. TeleCenters
  1430. Voice: 408-496-1800                                          Santa Clara, CA
  1431. uucp : {dual, hoptoad, hplabs, portal, ptsfa}!well!ustel
  1432.