/** * Parse a given command line * command - the command line to parse * request - the request to fill */ static ConsoleResult read_request(char* command, Request* request) { if ( command == NULL || request == NULL) { error_msg = "Internal error."; return ERROR; } char *token = strtok(command, " \t\n"); if (token == NULL) return IGNORE; if (strcmp(token, "help") == 0) { usage(); return IGNORE; } if (strcmp(token, "exit") == 0 || strcmp(token, "quit") == 0) return EXIT; // Make event if (strcmp(token, "add") == 0) { operation(request) = ADD; int res = fill_event(request); // The user supplied values are not being validated // If you want to do so, implement the validation functions // of file event.c and call them here return res; } else if (strcmp(token, "listall") == 0) { operation(request) = LIST_ALL; return OK; } else if (strcmp(token, "list") == 0) { //error_msg = "Not implemented."; operation(request) = LIST; int res = fill_id(request); return res; } else if (strcmp(token, "remove") == 0) { //error_msg = "Not implemented."; operation(request) = REMOVE; //request->event_op.type int res = fill_id(request); return res; } else { error_msg = "Unknown command."; return ERROR; } }
static void fill_utmpx (struct utmpx *utx, bool login, int pid, const char *line, const char *user, const char *host) { memset (utx, 0, sizeof (struct utmpx)); // posix says that ut_line is not meaningful for DEAD_PROCESS // records, but most implementations of last use ut_line to // associate records in wtmp file strncpy (utx->ut_line, line, sizeof (utx->ut_line)); fill_id (utx->ut_id, line, sizeof (utx->ut_id)); utx->ut_pid = pid; utx->ut_type = login ? USER_PROCESS : DEAD_PROCESS; utx->ut_tv.tv_sec = time (NULL); utx->ut_tv.tv_usec = 0; // posix says that ut_user is not meaningful for DEAD_PROCESS // records, but solaris utmp_update helper requires that the ut_user // field of a DEAD_PROCESS entry matches the one of an existing // USER_PROCESS entry for the same line, if any strncpy (utx->ut_user, user, sizeof (utx->ut_user)); if (login) { # ifdef HAVE_UTMPX_HOST strncpy (utx->ut_host, host, sizeof (utx->ut_host)); # endif } }
static void fill_utmp (struct utmp *ut, bool login, int pid, const char *line, const char *user, const char *host) { memset (ut, 0, sizeof (struct utmp)); strncpy (ut->ut_line, line, sizeof (ut->ut_line)); # ifdef HAVE_UTMP_PID fill_id (ut->ut_id, line, sizeof (ut->ut_id)); ut->ut_pid = pid; ut->ut_type = login ? USER_PROCESS : DEAD_PROCESS; # endif ut->ut_time = time (NULL); if (login) { # ifdef HAVE_UTMP_PID strncpy (ut->ut_user, user, sizeof (ut->ut_user)); # else strncpy (ut->ut_name, user, sizeof (ut->ut_name)); # endif # ifdef HAVE_UTMP_HOST strncpy (ut->ut_host, host, sizeof (ut->ut_host)); # endif } }
void init_ref_entry( ref_entry * re, char * id, size_t len ) { re->next = NULL; re->u.info.text_cap = NULL; fill_id( re, id, len ); if( input_cbs->fmflags & II_macro ) { re->lineno = input_cbs->s.m->lineno; } else { re->lineno = input_cbs->s.f->lineno; } re->u.info.number = 0; if( ProcFlags.page_started ) { re->u.info.pageno = page; } else { re->u.info.pageno = page + 1; } }
static void gml_ixxx_common( const gmltag * entry, int hx_lvl ) { bool idseen; bool refidseen; bool seeseen; bool seeidseen; bool pgseen; bool printseen; char * p; ereftyp pgvalue; char * pgtext; size_t pgtextlen; size_t printtxtlen; size_t seetextlen; char * printtxt; char * seetext; ref_entry * refwork; ref_entry reid; ref_entry * rewk; ref_entry refid; ref_entry * refwk; ref_entry reseeid; ref_entry * rswk; ix_h_blk * ihm1; ix_e_blk * ixewk; ix_e_blk * ixewksav; ix_h_blk * ixhwk; ix_h_blk * * ixhwork; uint32_t wkpage; size_t txtlen; char * txt; char hxstring[TAG_NAME_LENGTH +1]; char lvlc; if( !GlobalFlags.index ) { // index option not active scan_start = scan_stop + 1; // ignore tag return; } lvlc = '0' + (char)hx_lvl; *hxstring = GML_char; // construct tagname for possible error msg strcpy_s( (hxstring + 1), TAG_NAME_LENGTH, entry->tagname ); if( (hxstring[2] == lvlc) && // :Ix tags not allowed before :GDOC !((ProcFlags.doc_sect >= doc_sect_gdoc) || (ProcFlags.doc_sect_nxt >= doc_sect_gdoc)) ) { g_err( err_tag_before_gdoc, hxstring ); err_count++; file_mac_info(); scan_start = scan_stop + 1; return; } if( hx_lvl > 1 ) { // test for missing previous parent index tag if( ixhtag[hx_lvl - 1] == NULL ) { g_err( err_parent_undef ); err_count++; file_mac_info(); scan_start = scan_stop + 1; return; } } idseen = false; pgseen = false; refidseen = false; printseen = false; seeseen = false; seeidseen = false; ixewk = NULL; pgvalue = pgnone; pgtext = NULL; pgtextlen = 0; printtxt = NULL; printtxtlen = 0; seetext = NULL; wkpage = page + 1; p = scan_start; ProcFlags.tag_end_found = false; /***********************************************************************/ /* Scan attributes for :Ix :IHx :IREF */ /* */ /* id= */ /* refid= */ /* pg= */ /* print= */ /* see= */ /* seeid= */ /***********************************************************************/ for( ;; ) { if( ProcFlags.tag_end_found ) { break; } while( is_space_tab_char( *p ) ) { p++; } if( *p == '.' ) { ProcFlags.tag_end_found = true; break; } if( *p == '\0' ) { break; } /*******************************************************************/ /* ID='xxxxxxxx' for :Ix :IHx */ /*******************************************************************/ if( !strnicmp( "id", p, 2 ) ) { p += 2; p = get_refid_value( p ); if( (val_start != NULL) && (val_len > 0) ) { if( hx_lvl > 0 ) { // :Ix :IHx idseen = true; // id attribute found init_ref_entry( &reid, val_start, val_len ); rewk = find_refid( iref_dict, reid.id ); if( rewk != NULL ) { if( rewk->lineno != reid.lineno ) { g_err( inf_id_duplicate ); err_count++; file_mac_info(); scan_start = scan_stop + 1; return; } } } else { // not allowed for :IREF g_err( err_refid_not_allowed, hxstring ); err_count++; file_mac_info(); scan_start = scan_stop + 1; return; } } scan_start = p; continue; } /*******************************************************************/ /* REFID='xxxxxxxx' for :IREF :I2 :I3 */ /*******************************************************************/ if( !strnicmp( "refid", p, 5 ) ) { p += 5; p = get_refid_value( p ); if( val_start != NULL && val_len > 0 ) { if( (hx_lvl == 0) || ((hx_lvl > 1) && (hxstring[2] == lvlc)) ) { fill_id( &refid, val_start, val_len ); refidseen = true; // refid attribute found refwk = find_refid( iref_dict, refid.id ); if( refwk == NULL ) { // refid not in dict if( GlobalFlags.lastpass ) {// this is an error g_err( inf_id_unknown );// during lastpass err_count++; file_mac_info(); scan_start = scan_stop + 1; return; } } } else { // not allowed for :I1 and :IHx g_err( err_refid_not_allowed, hxstring ); err_count++; file_mac_info(); scan_start = scan_stop + 1; return; } } scan_start = p; continue; } /*******************************************************************/ /* PG= for :IREF :Ix */ /*******************************************************************/ if( !strnicmp( "pg", p, 2 ) ) { p += 2; p = get_att_value( p ); scan_start = p; if( val_start == NULL || val_len == 0 ) { // no valid pg continue; // ignore } if( quote_char == '\0' ) { // value not quoted if( !strnicmp( "start", val_start, 5 ) ) { pgvalue = pgstart; } else if( !strnicmp( "end", val_start, 3 ) ) { pgvalue = pgend; } else if( !strnicmp( "major", val_start, 5 ) ) { pgvalue = pgmajor; } else { continue; // ignore } } else { pgvalue = pgstring; pgtext = mem_alloc( val_len + 1 ); strncpy( pgtext, val_start, val_len );// use text instead of pageno *(pgtext + val_len) = '\0'; pgtextlen = val_len; } pgseen = true; continue; } /*******************************************************************/ /* PRINT= for :IHx */ /*******************************************************************/ if( !strnicmp( "print", p, 5 ) ) { p += 5; p = get_att_value( p ); scan_start = p; if( val_start == NULL || val_len == 0 ) { continue; // ignore } printtxt = mem_alloc( val_len + 1 ); printtxtlen = val_len; strncpy( printtxt, val_start, val_len ); *(printtxt + val_len) = '\0'; printseen = true; continue; } /*******************************************************************/ /* SEE='xxxxxxxx' for :IREF :IH1 :IH2 */ /*******************************************************************/ if( !strnicmp( "see", p, 3 ) ) { p += 3; p = get_att_value( p ); scan_start = p; if( (val_start != NULL) || val_len > 0 ) { if( hx_lvl == 0 || ((hx_lvl < 3) && (hxstring[3] == lvlc)) ) {// :IREF :IH1 :IH2 seetext = mem_alloc( val_len +1 ); strncpy( seetext, val_start, val_len ); *(seetext + val_len) = '\0'; seetextlen = val_len; seeseen = true; } else { // not allowed for :IH3, :Ix g_err( err_refid_not_allowed, hxstring ); err_count++; file_mac_info(); scan_start = scan_stop + 1; return; } } continue; } /*******************************************************************/ /* SEEID='xxxxxxxx' for :IREF :IH1 :IH2 */ /*******************************************************************/ if( !strnicmp( "seeid", p, 5 ) ) { p += 5; p = get_refid_value( p ); if( (val_start != NULL) && (val_len > 0) ) { if( (hx_lvl <= 3) && (hxstring[3] == lvlc) ) { seeidseen = true; fill_id( &reseeid, val_start, val_len );// copy lower id rswk = find_refid( iref_dict, reseeid.id ); if( rswk == NULL ) {// not in dict, this is an error if( GlobalFlags.lastpass ) { // during lastpass g_err( inf_id_unknown ); err_count++; file_mac_info(); scan_start = scan_stop + 1; return; } } } else { // not allowed for :IH3, :Ix :IREF g_err( err_refid_not_allowed, hxstring ); err_count++; file_mac_info(); scan_start = scan_stop + 1; return; } } scan_start = p; continue; } /*******************************************************************/ /* no more valid attributes */ /*******************************************************************/ break; } if( ProcFlags.tag_end_found ) { // tag end ? p++; if( hx_lvl > 0 ) { // we need a text line for :Ix :IHx if( !*p ) { get_line( true ); p = buff2; } } } /***********************************************************************/ /* process the found attributes and the text line */ /***********************************************************************/ txt = p; txtlen = strlen( p ); if( !pgseen ) { pgvalue = pgpageno; // set default } if( hx_lvl == 0 ) { // :IREF tag /***********************************************************************/ /* processing for :IREF */ /***********************************************************************/ if( !refidseen ) { // refid= missing g_err( err_att_missing ); err_count++; file_mac_info(); scan_start = scan_stop + 1; return; } if( GlobalFlags.lastpass ) { if( refidseen && (refwk != NULL) ) { ixhwk = refwk->u.refb.hblk; } else { ixhwk = ixhtag[hx_lvl]; } /***************************************************************/ /* create index entry with page no / text */ /***************************************************************/ if( ixhwk->entry == NULL ) { // first entry ixewk = fill_ix_e_blk( &(ixhwk->entry), ixhwk, pgvalue, pgtext, pgtextlen ); } else { if( pgvalue == pgmajor ) { // major becomes first in chain ixewksav = ixhwk->entry; ixhwk->entry = NULL; ixewk = fill_ix_e_blk( &(ixhwk->entry), ixhwk, pgvalue, pgtext, pgtextlen ); ixewk->next = ixewksav; } else { ixewk = ixhwk->entry; if( pgvalue < pgstring ) { // pageno variants if( ixewk->entry_typ < pgstring ) { while( ixewk->next != NULL ) {// insert before pgstring if( ixewk->next->entry_typ >= pgstring ) { break; } ixewk = ixewk->next; } } else { ixewksav = ixhwk->entry; ixhwk->entry = NULL; ixewk = fill_ix_e_blk( &(ixhwk->entry), ixhwk, pgvalue, pgtext, pgtextlen ); ixewk->next = ixewksav; } if( ixewk->u.page_no != wkpage ) { ixewksav = ixewk->next; ixewk->next = NULL; ixewk = fill_ix_e_blk( &(ixewk->next), ixhwk, pgvalue, pgtext, pgtextlen ); ixewk->next = ixewksav; } } else { while( ixewk->next != NULL ) { // find last entry ixewk = ixewk->next; } ixewk = fill_ix_e_blk( &(ixewk->next), ixhwk, pgvalue, pgtext, pgtextlen ); } } } } } else // :Ix :IHx tags if( ((hxstring[2] == lvlc) ) ) { // test for :Ix /***********************************************************************/ /* processing for :Ix */ /***********************************************************************/ switch( hx_lvl ) { // processing for :I1 :I2 :I3 case 1 : ixhwork = &index_dict; ixhwk = find_create_ix_h_entry( ixhwork, &printtxt, printtxtlen, txt, txtlen, hx_lvl ); printtxt = NULL; ixhtag[hx_lvl] = ixhwk; break; case 2 : case 3 : ihm1 = ixhtag[hx_lvl - 1]; if( refidseen && (refwk != NULL) ) { if( hx_lvl > refwk->u.refb.hblk->ix_lvl ) { ixhwork = &(refwk->u.refb.hblk->lower); } else { ixhwork = &(refwk->u.refb.hblk); } } else { ixhwork = &(ixhtag[hx_lvl - 1]->lower); } ixhwk = find_create_ix_h_entry( ixhwork, &printtxt, printtxtlen, txt, txtlen, hx_lvl ); printtxt = NULL; if( !refidseen ) { ixhtag[hx_lvl] = ixhwk; } break; default: break; } /*******************************************************************/ /* create index entry with page no / text */ /*******************************************************************/ if( ixhwk->entry == NULL ) { // first entry ixewk = fill_ix_e_blk( &(ixhwk->entry), ixhwk, pgvalue, pgtext, pgtextlen ); } else { if( pgvalue == pgmajor ) { // major becomes first in chain ixewksav = ixhwk->entry; ixhwk->entry = NULL; ixewk = fill_ix_e_blk( &(ixhwk->entry), ixhwk, pgvalue, pgtext, pgtextlen ); ixewk->next = ixewksav; } else { ixewk = ixhwk->entry; if( pgvalue < pgstring ) { // pageno variants if( ixewk->entry_typ < pgstring ) { while( ixewk->next != NULL ) {// insert before pgstring if( ixewk->next->entry_typ >= pgstring ) { break; } ixewk = ixewk->next; } } else { ixewksav = ixhwk->entry; ixhwk->entry = NULL; ixewk = fill_ix_e_blk( &(ixhwk->entry), ixhwk, pgvalue, pgtext, pgtextlen ); ixewk->next = ixewksav; } if( ixewk->u.page_no != wkpage ) { ixewksav = ixewk->next; ixewk->next = NULL; ixewk = fill_ix_e_blk( &(ixewk->next), ixhwk, pgvalue, pgtext, pgtextlen ); ixewk->next = ixewksav; } } else { while( ixewk->next != NULL ) { // find last entry ixewk = ixewk->next; } ixewk = fill_ix_e_blk( &(ixewk->next), ixhwk, pgvalue, pgtext, pgtextlen ); } } } } else // :IHx if( ((hxstring[3] == lvlc) ) ) { // test for :IHx /***********************************************************************/ /* processing for :IHx */ /***********************************************************************/ switch( hx_lvl ) { // processing for :IH1 :IH2 :IH3 case 1 : ixhwork = &index_dict; ixhwk = find_create_ix_h_entry( ixhwork, &printtxt, printtxtlen, txt, txtlen, hx_lvl ); printtxt = NULL; ixhtag[hx_lvl] = ixhwk; break; case 2 : case 3 : ihm1 = ixhtag[hx_lvl - 1]; ixhwork = &(ixhtag[hx_lvl - 1]->lower); ixhwk = find_create_ix_h_entry( ixhwork, &printtxt, printtxtlen, txt, txtlen, hx_lvl ); printtxt = NULL; ixhtag[hx_lvl] = ixhwk; break; default: break; } if( seeseen ) { pgvalue = pgsee; if( ixhwk->entry == NULL ) { ixewk = fill_ix_e_blk( &(ixhwk->entry), ixhwk, pgvalue, seetext, seetextlen ); } else { ixewk = ixhwk->entry; while( ixewk->next != NULL ) { // find last entry ixewk = ixewk->next; } ixewk = fill_ix_e_blk( &(ixewk->next), ixhwk, pgvalue, seetext, seetextlen ); } } else { if( seeidseen ) { ix_e_blk * * anchor; pgvalue = pgsee; if( ixhwk->entry == NULL ) { anchor = &(ixhwk->entry); } else { ixewk = ixhwk->entry; while( ixewk->next != NULL ) { // find last entry ixewk = ixewk->next; } anchor = &(ixewk->next); } if( rswk->u.refb.hblk->prt_term != NULL ) { ixewk = fill_ix_e_blk( anchor, ixhwk, pgvalue, rswk->u.refb.hblk->prt_term, rswk->u.refb.hblk->prt_term_len ); } else { ixewk = fill_ix_e_blk( anchor, ixhwk, pgvalue, rswk->u.refb.hblk->ix_term, rswk->u.refb.hblk->ix_term_len ); } } } } if( idseen ) { // ID specified create reference entry reid.u.refb.hblk = ixhwk; reid.u.refb.eblk = ixewk; reid.flags = rf_ix; refwork = mem_alloc( sizeof( reid ) ); memcpy( refwork, &reid, sizeof( reid ) ); add_ref_entry( &iref_dict, refwork ); } if( pgtext != NULL ) { mem_free( pgtext ); } if( printtxt != NULL ) { mem_free( printtxt ); } if( seetext != NULL ) { mem_free( seetext ); } scan_start = scan_stop + 1; return; }
static void gml_hx_common( gml_tag gtag, int hx_lvl ) { char * p; char * headp; bool idseen; bool stitleseen; int rc; int k; size_t headlen; size_t txtlen; char hnumstr[64]; ref_entry * re; ref_entry * rwk; static char hxstr[4] = ":HX"; static char htextx[8] = "$htextX"; static char headx[7] = "$headX"; gtag = gtag; *(hxstr + 2) = '0' + hx_lvl; htextx[6] = '0' + hx_lvl; hnumx[5] = '0' + hx_lvl; headx[5] = '0' + hx_lvl; switch( hx_lvl ) { case 0: if( !((ProcFlags.doc_sect == doc_sect_body) || (ProcFlags.doc_sect_nxt == doc_sect_body)) ) { g_err( err_tag_wrong_sect, hxstr, ":BODY section" ); err_count++; file_mac_info(); } break; case 1: if( !((ProcFlags.doc_sect >= doc_sect_body) || (ProcFlags.doc_sect_nxt >= doc_sect_body)) ) { g_err( err_tag_wrong_sect, hxstr, ":BODY :APPENDIX :BACKM sections" ); err_count++; file_mac_info(); } break; default: if( !((ProcFlags.doc_sect >= doc_sect_abstract) || (ProcFlags.doc_sect_nxt >= doc_sect_abstract)) ) { g_err( err_tag_wrong_sect, hxstr, ":ABSTRACT section or later" ); err_count++; file_mac_info(); } break; } if( layout_work.hx[hx_lvl].number_form != num_none ) { layout_work.hx[hx_lvl].headn++; } idseen = false; stitleseen = false; p = scan_start; re = NULL; /***********************************************************************/ /* Scan attributes for :Hx */ /* id= */ /* stitle= */ /***********************************************************************/ for( ;; ) { while( *p == ' ' ) { p++; } if( *p == '\0' || *p == '.' ) { break; // tag end found } if( !strnicmp( "stitle=", p, 7 ) ) { p += 6; stitleseen = true; /***************************************************************/ /* Although unsupported scan stitle='xxx' */ /***************************************************************/ g_warn( wng_unsupp_att, "stitle" ); wng_count++; file_mac_info(); p = get_att_value( p ); scan_start = p; if( !ProcFlags.tag_end_found ) { continue; } break; } /*******************************************************************/ /* ID='xxxxxxxx' */ /*******************************************************************/ if( !strnicmp( "id=", p, 3 ) ) { p += 2; p = get_refid_value( p ); if( val_len > 0 ) { idseen = true; // valid id attribute found *(val_start + val_len) = '\0'; if( re == NULL ) { // prepare reference entry re = mem_alloc( sizeof( ref_entry ) ); init_ref_entry( re, val_start, val_len ); } else { fill_id( re, val_start, val_len ); } } scan_start = p; if( !ProcFlags.tag_end_found ) { continue; } break; } /*******************************************************************/ /* no more valid attributes, process remaining input as header text*/ /*******************************************************************/ break; } if( *p == '.' ) { // tag end ? p++; } /************************************************************************/ /* set the global vars $headx, $headnumx, $htextx */ /* perhaps text translated to upper or lower case */ /************************************************************************/ while( *p == ' ' ) { // ignore leading blanks p++; } if( *p ) { // text exists if( layout_work.hx[hx_lvl].cases == case_lower ) { strlwr( p ); } else if( layout_work.hx[hx_lvl].cases == case_upper ) { strupr( p ); } } rc = add_symvar( &global_dict, htextx, p, no_subscript, 0 ); update_headnumx( hx_lvl, hnumstr, sizeof( hnumstr ) ); txtlen = strlen( p ); headlen = strlen( hnumstr) + txtlen + 2; headp = mem_alloc( headlen ); if( layout_work.hx[hx_lvl].number_form != num_none ) { strcpy( headp, hnumstr); // numbered header strcat( headp, " " ); } else { *headp = '\0'; } strcat( headp, p ); rc = add_symvar( &global_dict, headx, headp, no_subscript, 0 ); out_msg( " %s\n", headp ); // always verbose output ? TBD mem_free( headp ); /***********************************************************************/ /* if id specified add it to reference dict */ /***********************************************************************/ if( idseen ) { rwk = find_refid( ref_dict, re->id ); if( !rwk ) { // new entry if( txtlen > 0 ) { // text line not empty re->u.info.text_cap = mem_alloc( txtlen + 1 ); strcpy( re->u.info.text_cap, p ); } add_ref_entry( &ref_dict, re ); re = NULL; // free will be done via dictionary } else { /***************************************************************/ /* test for duplicate id */ /* it is done with comparing line no only, in the hope that */ /* two identical ids are not specified in different files on */ /* the same line no. */ /***************************************************************/ if( re->lineno != rwk->lineno ) { g_err( wng_id_xxx, re->id ); g_info( inf_id_duplicate ); file_mac_info(); err_count++; } if( re->u.info.text_cap != NULL ) { mem_free( re->u.info.text_cap ); } mem_free( re ); } } if( layout_work.hx[hx_lvl].number_reset ) { for( k = hx_lvl + 1; k < 7; k++ ) { layout_work.hx[k].headn = 0;// reset following levels if( layout_work.hx[k].headnsub != NULL ) { *(layout_work.hx[k].headnsub->value) = '\0'; } } } /***********************************************************************/ /* creation of actual heading */ /***********************************************************************/ /***********************************************************************/ /* eject page(s) if specified */ /***********************************************************************/ if( layout_work.hx[hx_lvl].page_eject != ej_no ) { if( ProcFlags.page_started ) { do_page_out(); reset_t_page(); } if( !ProcFlags.start_section ) { start_doc_sect(); } set_headx_banners( hx_lvl ); // set possible banners reset_t_page(); // and adjust page margins if( (layout_work.hx[hx_lvl].page_eject == ej_odd) && (page & 1) ) { do_page_out(); // next page would be even reset_t_page(); } else if( (layout_work.hx[hx_lvl].page_eject == ej_even) && !(page & 1) ) { do_page_out(); // next page would be odd reset_t_page(); } } if( layout_work.hx[hx_lvl].display_heading ) { hx_header( hx_lvl, hnumstr, p ); } scan_start = scan_stop; return; }