void main(int argc, char *argv[]) { char buf[ MAXBUF+1 ]; SIflush(stdin); gets(buf); /* SIgetrec(buf, MAXBUF, stdin); */ SIputrec(buf, stdout); }
STATUS read_in_comments(FILE *aFile, FILE *comPtr) { STATUS ret_status = OK ; do { if ((ret_status = read_fm_command(aFile)) == OK) { if (sep_state&IN_COMMENT_STATE) { SIputrec(buffer_1,comPtr); } } } while ((sep_state&IN_COMMENT_STATE)&&(ret_status == OK)); return(ret_status); }
/*{ ** 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); }
STATUS Run_SED_on_file(SEPFILE **Sep_file,LOCATION *Sep_Loc) { STATUS ret_val ; CL_ERR_DESC cl_err; LOCATION *sedtmploc = NULL ; LOCATION *filtmploc = NULL ; char *SEDbuffer = NULL ; char *sedtmp = NULL ; char *filtmp = NULL ; char *cmd_line = NULL ; char *sed_dev = NULL ; char *sed_path = NULL ; char *sed_name = NULL ; char *sed_type = NULL ; char *sed_vers = NULL ; char *fptr1 = NULL ; char *fptr2 = NULL ; FILE *SEDfptr = NULL ; FILE *fptr = NULL ; bool Sep_file_empty ; sed_dev = SEP_MEalloc(SEP_ME_TAG_SED, LO_DEVNAME_MAX+1, TRUE, NULL); sed_path = SEP_MEalloc(SEP_ME_TAG_SED, LO_PATH_MAX+1, TRUE, NULL); sed_name = SEP_MEalloc(SEP_ME_TAG_SED, LO_FPREFIX_MAX+1, TRUE, NULL); sed_type = SEP_MEalloc(SEP_ME_TAG_SED, LO_FSUFFIX_MAX+1, TRUE, NULL); sed_vers = SEP_MEalloc(SEP_ME_TAG_SED, LO_FVERSION_MAX+1, TRUE, NULL); SEDbuffer = SEP_MEalloc(SEP_ME_TAG_SED, SCR_LINE+1, TRUE, NULL); /* ** Create Sed output file names. */ sedtmploc = (LOCATION *)SEP_MEalloc(SEP_ME_TAG_SED, sizeof(LOCATION), TRUE, NULL); filtmploc = (LOCATION *)SEP_MEalloc(SEP_ME_TAG_SED, sizeof(LOCATION), TRUE, NULL); sedtmp = SEP_MEalloc(SEP_ME_TAG_TOKEN, MAX_LOC+1, TRUE, NULL); filtmp = SEP_MEalloc(SEP_ME_TAG_TOKEN, MAX_LOC+1, TRUE, NULL); LOtos(Sep_Loc, &fptr2); STcopy(fptr2, sedtmp); STcopy(fptr2, filtmp); LOfroms(FILENAME & PATH, sedtmp, sedtmploc); LOfroms(FILENAME & PATH, filtmp, filtmploc); LOdetail(sedtmploc, sed_dev, sed_path, sed_name, sed_type, sed_vers); STcopy(ERx("sed"),sed_type); SEP_LOcompose(sed_dev, sed_path, sed_name, sed_type, sed_vers, sedtmploc); STcopy(ERx("sdr"),sed_type); SEP_LOcompose(sed_dev, sed_path, sed_name, sed_type, sed_vers, filtmploc); /* ** Copy Sep SI_RACC file to a SI_TXT file. */ SEPrewind(*Sep_file, FALSE); if ((ret_val = SIfopen(filtmploc,ERx("w"), SI_TXT, SCR_LINE, &fptr)) != OK) return(ret_val); for (Sep_file_empty = TRUE; (ret_val = SEPgetrec(SEDbuffer, *Sep_file)) == OK; SIputrec(SEDbuffer, fptr)) if (Sep_file_empty) Sep_file_empty = FALSE; SIclose(fptr); if (Sep_file_empty == FALSE) { /* ** Create command line for sed command. */ LOtos(SED_loc, &fptr1); LOtos(filtmploc, &fptr2); cmd_line = SEP_MEalloc(SEP_ME_TAG_TOKEN, MAX_LOC+1, TRUE, NULL); IISTprintf(cmd_line, "sed -f %s %s", fptr1, fptr2); /* ** Close Sep file and run the SED. */ SEPclose(*Sep_file); ret_val = PCcmdline(NULL, cmd_line, PC_WAIT, sedtmploc, &cl_err); if(ret_val != OK) { SEPopen(Sep_Loc, SCR_LINE, Sep_file); del_floc(sedtmploc); del_floc(filtmploc); MEtfree(SEP_ME_TAG_SED); return(1); } /* ** Recreate Sep file. */ #ifdef NT_GENERIC LOdelete(Sep_Loc); #else del_floc(Sep_Loc); #endif if ((ret_val = SIfopen(Sep_Loc, ERx("w"), SI_RACC, SCR_LINE, &fptr)) != OK) return(ret_val); SIclose(fptr); SEPopen(Sep_Loc, SCR_LINE, Sep_file); /* ** Open Sed output file. */ if ((ret_val = SIfopen(sedtmploc, ERx("r"), SI_TXT, SCR_LINE, &SEDfptr)) != OK) return(ret_val); /* ** Copy the Sed output file to the Sep file. */ while((ret_val = SIgetrec(SEDbuffer, SCR_LINE, SEDfptr)) == OK) SEPputrec(SEDbuffer, *Sep_file); SEPclose(*Sep_file); SIclose(SEDfptr); /* ** Reopen the sep file. */ SEPopen(Sep_Loc, SCR_LINE, Sep_file); /* ** Clean up. */ del_floc(sedtmploc); } del_floc(filtmploc); MEtfree(SEP_ME_TAG_SED); return(OK); }
i4 Trace_Token_List(char *list_label,i4 l_nr,i4 num_of_tokens,FILE_TOKENS **tokarray) { i4 i, j, k ; char *toktype = NULL ; char *otoktype = NULL ; bool skip_it = FALSE ; char *ARRY_LINE_FMT = ERx(" %5d %-40s %5d A_%-10s\n") ; char *ARRY_BANNER = ERx("-------------------------------------------------------------------------\n") ; SIfprintf(traceptr,ERx("\n %6s #%d, %d Tokens.\n\n"), list_label, l_nr, num_of_tokens ); if (num_of_tokens == 0) return (OK); SIputrec(ARRY_BANNER,traceptr); SIputrec(ERx(" Token | First 40 Chars "), traceptr); SIputrec(ERx(" | Line | Token\n"), traceptr); SIputrec(ERx(" Nr | of Token "), traceptr); SIputrec(ERx(" | Nr | Type\n"), traceptr); SIputrec(ARRY_BANNER,traceptr); for (i=1, j=0; i <= num_of_tokens; i++) { if ((j == 0)||(tokarray[i]->tokenID != A_UNKNOWN)|| (STcompare(tokarray[i]->token,tokarray[j]->token) != 0)) { if (skip_it == TRUE) { if ((k = tokarray[i]->token_no - tokarray[j]->token_no) == 2) { SIfprintf(traceptr, ARRY_LINE_FMT, tokarray[j]->token_no, tokarray[j]->token, tokarray[j]->lineno, otoktype ); } else { SIfprintf(traceptr, ERx("\t\t - (%d) duplicate tokens -\n"), k-1); } skip_it = FALSE; } j = i; } else { otoktype = toktype; skip_it = TRUE; continue; } switch (tokarray[i]->tokenID) { case A_NUMBER: toktype = ERx("NUMBER"); break; case A_OCTAL: toktype = ERx("OCTAL"); break; case A_HEXA: toktype = ERx("HEXA"); break; case A_FLOAT: toktype = ERx("FLOAT"); break; case A_WORD: toktype = ERx("WORD"); break; case A_DBLWORD: toktype = ERx("DBLWORD"); break; case A_DATE: toktype = ERx("DATE"); break; case A_TIME: toktype = ERx("TIME"); break; case A_DELIMITER: toktype = ERx("DELIMITER"); break; case A_CONTROL: toktype = ERx("CONTROL"); break; case A_UNKNOWN: toktype = ERx("UNKNOWN"); break; case A_RETCOLUMN: toktype = ERx("RETCOLUMN"); break; case A_DIRECTORY: toktype = ERx("DIRECTORY"); break; case A_BANNER: toktype = ERx("BANNER"); break; case A_PRODUCT: toktype = ERx("PRODUCT"); break; case A_VERSION: toktype = ERx("VERSION"); break; case A_ALARMID: toktype = ERx("ALARMID"); break; case A_COMPNAME: toktype = ERx("COMPNAME"); break; case A_COPYRIGHT: toktype = ERx("COPYRIGHT"); break; case A_DBNAME: toktype = ERx("DBNAME"); break; case A_DESTROY: toktype = ERx("DESTROY"); break; case A_DROP: toktype = ERx("DROP"); break; case A_RULE: toktype = ERx("RULE"); break; case A_PROCEDURE: toktype = ERx("PROCEDURE"); break; case A_SPACE: toktype = ERx("SPACE"); break; case A_DATABSID: toktype = ERx("DATABSID"); break; case A_TRANID: toktype = ERx("TRANID"); break; case A_SERVERID: toktype = ERx("SERVERID"); break; case A_TABLE: toktype = ERx("TABLE"); break; case A_OWNER: toktype = ERx("OWNER"); break; case A_USER: toktype = ERx("USER"); break; case A_COLUMN: toktype = ERx("COLUMN"); break; case A_GROUP: toktype = ERx("GROUP"); break; case A_COMPILE: toktype = ERx("COMPILE"); break; default: toktype = ERx("(error)"); break; } SIfprintf(traceptr, ARRY_LINE_FMT, tokarray[i]->token_no, tokarray[i]->token, tokarray[i]->lineno, toktype ); } SIfprintf(traceptr, ERx("(%5d)\n"), num_of_tokens); return (OK); }