/* ** insert_comment () */ STATUS insert_comment () { STATUS ret_val ; OFFSET_TYPE size ; if ((ret_val = bld_cmtName(msg)) != OK) { disp_line(msg, 0, 0); } else if (SEP_LOexists(cmtLoc)) { LOsize(cmtLoc, &size); if (size > 0) { append_line(OPEN_COMMENT, 1); append_file(cmtName); append_line(CLOSE_COMMENT, 1); } del_floc(cmtLoc); } return (ret_val); } /* end of insert_comment */
/*{ ** Name: NMwritesyms - write the symbol table list to file. ** ** Description: ** Write the symbol table list back out to the file. ** ** This duplicates the function in ingunset.c, but shouldn't be in ** compatlib because no one else has any business writing the file. ** ** Inputs: ** none. ** ** Output: ** none. ** ** Returns: ** OK Function completed normally. ** FAIL Function completed abnormally. ** ** History: ** 20-jul-87 (mmm) ** Updated to meet jupiter standards. ** 14-apr-89 (arana) ** When LOlast was added to update symbol table mod time, ** return value was saved off but not returned. ** 15-jul-93 (ed) ** adding <gl.h> after <compat.h> ** 29-sep-94 (cwaldman) ** Changed check of NMopensyms return value to compare against ** (FILE *)NULL (was NULL). ** Changed write routine to write into a temporary file first, ** check whether this file has been written OK, and rename ** temporary file to symbol.tbl if it is alright. This is part ** of the fix for bug 44445 (symbol.tbl disappears). There is ** still a slight chance of something going wrong during the ** rename, but in that case variables are at least preserved ** in symbol.tmp. ** 19-oct-94 (abowler) ** Minor correction to change above. Cal to SIopen should be ** passed address of location structure. (Didn't show up as ** a bug on su4_u42 !) ** 28-feb-95 (cwaldman) ** Amendment to change on 29 Sep. Part of the check whether ** the temporary symbol table had been written OK was to check ** the file size. The check would return the file size if ** check was OK and 0 otherwise. If a 0 was returned, the old ** symbol.tbl would not be replaced. This made it impossible ** to 'ingunset' the last variable in a symbol.tbl. Changed ** 'OK-check' to use -1 as error indicator. ** 02-jul-1996 (sweeney) ** Apply umask fix (bug #71890) from ingres63p ** 07-apr-2004 (somsa01) ** Added backup of symbol.tbl logic. */ STATUS NMwritesyms() { register SYM *sp; FILE *fp, *tfp = NULL; register i4 status = OK; register i4 closestat; char buf[ MAXLINE + NULL_NL_NULL ]; char tbuf[ MAXLINE + NULL_NL_NULL ]; i4 flagword, size, symcount = 0, bksymcount; STATUS retval; LOCATION t_loc; LOINFORMATION loinfo; bool perform_backup = TRUE; OFFSET_TYPE bk_size; /* ** ensure sensible umask for symbol.tmp, as it will become symbol.tbl */ PEsave(); PEumask("rw-r--"); if ((FILE *)NULL == (fp = NMopensyms( "r" ))) { PEreset(); return (NM_STOPN); } SIclose(fp); LOcopy(&NMSymloc, tbuf, &t_loc); if ( OK != LOfstfile("symbol.tmp", &t_loc) || OK != SIopen(&t_loc, "w", &tfp)) { return (NM_STOPN); } for ( sp = s_list; sp != NULL; sp = sp->s_next ) { (VOID) STpolycat( 3, sp->s_sym, "\t", sp->s_val, buf ); STmove( buf, ' ', MAXLINE, buf ); buf[ MAXLINE - 1 ] = '\n'; buf[ MAXLINE ] = '\0'; if ( OK != (status = SIputrec(buf, tfp))) break; symcount++; } /* Very interested in close status of file being written */ closestat = SIclose( tfp ); flagword = (LO_I_SIZE); size = (OK == LOinfo(&t_loc,&flagword,&loinfo) ? loinfo.li_size : -1); retval=(status != OK || closestat != OK || size == -1 ? NM_STAPP : OK); /* if file written ok update modification time */ if(retval == OK) { LOrename(&t_loc, &NMSymloc); LOlast(&NMSymloc, &NMtime); #if defined(su4_cmw) /* Now reset the old MAC label if any */ if (NM_got_label) { (void)setcmwlabel(NM_path, &NM_saved_label, SETCL_ALL); NM_got_label=0; } #endif /* ** If we have no backup to check against, just do it. Otherwise, ** make sure our new symbol table differs from the backup by at most ** one symbol before performing a backup. */ if (LOexist(&NMBakSymloc) == OK) { LOsize(&NMBakSymloc, &bk_size); bksymcount = (i4)(bk_size / (MAXLINE + 1)); if (bksymcount != symcount && bksymcount != symcount - 1 && bksymcount != symcount + 1) { perform_backup = FALSE; } } if (perform_backup) { if (SIopen(&NMBakSymloc, "w", &tfp) == OK) { for (sp = s_list; sp != NULL; sp = sp->s_next) { STpolycat(3, sp->s_sym, "\t", sp->s_val, buf); STmove(buf, ' ', MAXLINE, buf); buf[MAXLINE - 1] = '\n'; buf[MAXLINE] = '\0'; if ((status = SIputrec(buf, tfp)) != OK) break; } SIclose(tfp); } } } PEreset(); return (retval); }