/* * EnterHexKey - enter a hexidecimal key stroke and insert it into the text */ vi_rc EnterHexKey( void ) { int i; char st[MAX_STR], val; vi_rc rc; const char *ptr; rc = ModificationTest(); if( rc != ERR_NO_ERR ) { return( rc ); } if( CurrentLine->len >= EditVars.MaxLine - 1 ) { return( ERR_LINE_FULL ); } rc = PromptForString( "Enter the number of char to insert:", st, sizeof( st ) - 1, NULL ); if( rc != ERR_NO_ERR ) { if( rc == NO_VALUE_ENTERED ) { return( ERR_NO_ERR ); } return( rc ); } /* * get value */ ptr = SkipLeadingSpaces( st ); val = (char)strtol( ptr, NULL, 0 ); if( val == '\0' ) { return( ERR_INVALID_VALUE ); } /* * build undo record */ StartUndoGroup( UndoStack ); CurrentLineReplaceUndoStart(); CurrentLineReplaceUndoEnd( true ); EndUndoGroup( UndoStack ); /* * add the char */ GetCurrentLine(); for( i = WorkLine->len; i >= CurrentPos.column - 1; i-- ) { WorkLine->data[i + 1] = WorkLine->data[i]; } WorkLine->data[CurrentPos.column - 1] = val; WorkLine->len++; DisplayWorkLine( true ); if( CurrentPos.column < WorkLine->len ) { GoToColumn( CurrentPos.column + 1, WorkLine->len + 1 ); } ReplaceCurrentLine(); EditFlags.Dotable = true; return( ERR_NO_ERR ); } /* EnterHexKey */
bool GenericQueryBool( char *str ) { #ifdef __WIN__ return( MessageBox( root_window_id, str, EditorName, MB_OKCANCEL ) == IDOK ); #else #define BUFLEN 10 char buffer[BUFLEN]; PromptForString( str, buffer, BUFLEN, NULL ); return( tolower( buffer[0] ) == 'y' ); #endif }
/* * GetResponse - get a response from the user */ vi_rc GetResponse( char *str, char *res ) { vi_rc rc; rc = PromptForString( str, res, MAX_STR, NULL ); if( rc == ERR_NO_ERR ) { return( GOT_RESPONSE ); } return( rc ); } /* GetResponse */
vi_rc Filter( range *r ) { vi_rc rc; char cmd[MAX_STR]; rc = PromptForString( "Command: ", cmd, sizeof( cmd ), &EditVars.Hist[HIST_FILTER] ); if( rc == ERR_NO_ERR ) { rc = DoGenericFilter( r->start.line, r->end.line, cmd ); } else { if( rc == NO_VALUE_ENTERED ) { rc = ERR_NO_ERR; } } return( rc ); } /* Filter */
/* * doProcessCommandLine - handle getting and processing a command line */ static vi_rc doProcessCommandLine( bool is_fancy ) { vi_rc rc; char *st; /* * open the window and get the string */ st = MemAllocUnsafe( EditVars.MaxLine ); if( st == NULL ) { return( ERR_NO_MEMORY ); } is_fancy = is_fancy; #ifdef __WIN__ if( is_fancy ) { if( !GetCmdDialog( st, EditVars.MaxLine ) ) { MemFree( st ); return( ERR_NO_ERR ); } } else { #endif rc = PromptForString( ":", st, EditVars.MaxLine, &EditVars.CLHist ); if( rc != ERR_NO_ERR ) { MemFree( st ); if( rc == NO_VALUE_ENTERED ) { return( ERR_NO_ERR ); } return( rc ); } #ifdef __WIN__ } #endif CommandBuffer = st; rc = SourceHook( SRC_HOOK_COMMAND, ERR_NO_ERR ); if( rc == ERR_NO_ERR ) { rc = RunCommandLine( st ); } CommandBuffer = NULL; MemFree( st ); return( rc ); } /* doProcessCommandLine */
/* * getFindString - get string and search for it */ static vi_rc getFindString( range *r, bool is_forward, bool is_fancy, bool search_again ) { vi_rc rc; char st[MAX_INPUT_LINE + 1]; char *res; char *prompt; #ifdef __WIN__ bool old_ci; bool old_sw; bool old_no; fancy_find ff; #endif is_fancy = is_fancy; search_again = search_again; #ifdef __WIN__ old_ci = EditFlags.CaseIgnore; old_sw = EditFlags.SearchWrap; old_no = EditFlags.NoReplaceSearchString; if( is_fancy ) { if( lastFindStr != NULL ) { strcpy( st, lastFindStr ); ff.use_regexp = lastFindWasRegExp; ff.case_ignore = lastFindWasCaseIgnore; ff.search_forward = is_forward; ff.search_wrap = lastFindWasWrap; } else { st[0] = 0; } ff.find = st; ff.findlen = sizeof( st ); if( !search_again ) { if( !GetFindStringDialog( &ff ) ) { return( RANGE_REQUEST_CANCELLED ); } } else { st[0] = 0; EditFlags.NoReplaceSearchString = TRUE; } is_forward = ff.search_forward; EditFlags.CaseIgnore = ff.case_ignore; EditFlags.SearchWrap = ff.search_wrap; if( !ff.use_regexp ) { /* we need to add the string without any changes */ if( !EditFlags.NoReplaceSearchString ) { AddString2( &lastFindStr, st ); lastFindWasRegExp = FALSE; } MakeExpressionNonRegular( st ); } res = st; } else { #endif if( is_forward ) { prompt = "/"; } else { prompt = "?"; } st[0] = prompt[0]; rc = PromptForString( prompt, st + 1, sizeof( st ) - 1, &FindHist ); if( rc != ERR_NO_ERR ) { if( rc == NO_VALUE_ENTERED ) { return( ERR_NO_ERR ); } return( rc ); } res = &st[1]; // skip prompt #ifdef __WIN__ } #endif if( is_forward ) { rc = processFind( r, res, GetFindForward ); } else { rc = processFind( r, res, GetFindBackwards ); } #ifdef __WIN__ EditFlags.NoReplaceSearchString = old_no; EditFlags.CaseIgnore = old_ci; EditFlags.SearchWrap = old_sw; lastFindWasRegExp = ff.use_regexp; lastFindWasCaseIgnore = ff.case_ignore; lastFindWasForward = ff.search_forward; lastFindWasWrap = ff.search_wrap; #endif EditFlags.LastSearchWasForward = is_forward; return( rc ); } /* getFindString */
int main(int argc,char *argv[]) { char logname[BUFSIZ]={0}; char *host; char *user; char *passwd; char user_agent[255]={0}; char ticket[41]=""; /* Get the Rivendell Host, User and Password if set in env */ if (getenv("RIVHOST")!=NULL) { host = getenv("RIVHOST"); } else { host="localhost"; } if (getenv("RIVUSER")!=NULL) { user = getenv("RIVUSER"); } else { user="******"; } if (getenv("RIVPASS")!=NULL) { passwd = getenv("RIVPASS"); } else { passwd = ""; } PromptForString("Please enter the Name of the Log that you want to Delete ==> ", logname,BUFSIZ); // Add the User Agent and Version strcat(user_agent,RD_GetUserAgent()); strcat(user_agent,RD_GetVersion()); strcat(user_agent," (Test Suite)"); // // Call the function // int result=RD_DeleteLog(host, user, passwd, ticket, logname, user_agent); if(result<0) { fprintf(stderr,"Something went wrong!\n"); exit(256); } if ((result< 200 || result > 299) && (result != 0)) { switch(result) { case 400: fprintf(stderr," ERROR: Invalid Parameter for LOG_NAME! \n"); break; case 500: fprintf(stderr, "ERROR: Unable to Delete Log! \n"); break; default: fprintf(stderr, "Unknown Error occurred ==> %d",result); } exit(256); } // // List the Results // printf(" Success\n"); exit(0); }
int main(int argc,char *argv[]) { char logname[BUFSIZ]={0}; char servicename[BUFSIZ]={0}; char *host; char *user; char *passwd; char ticket[41]=""; char user_agent[255]={0}; /* Get the Rivendell Host, User and Password if set in env */ if (getenv("RIVHOST")!=NULL) { host = getenv("RIVHOST"); } else { host="localhost"; } if (getenv("RIVUSER")!=NULL) { user = getenv("RIVUSER"); } else { user="******"; } if (getenv("RIVPASS")!=NULL) { passwd = getenv("RIVPASS"); } else { passwd = ""; } PromptForString("Please enter the Name of the Log that you want to Add ==> ", logname,BUFSIZ); PromptForString("Please enter the Name of the Service for the log that you want to Add ==> ", servicename,BUFSIZ); // Add the User Agent and Version strcat(user_agent,RD_GetUserAgent()); strcat(user_agent,RD_GetVersion()); strcat(user_agent," (Test Suite)"); // // Call the function // int result=RD_AddLog(host, user, passwd, ticket, logname, servicename, user_agent); if(result<0) { fprintf(stderr,"Something went wrong!\n"); exit(256); } if ((result< 200 || result > 299) && (result != 0)) { switch(result) { case 400: fprintf(stderr," ERROR: Invalid Parameter for LOG_NAME or SERVICE_NAME"); break; case 404: fprintf(stderr,"ERROR: No Such Service Exists! \n"); break; case 500: fprintf(stderr, "ERROR: Unable to Create Log! \n"); break; default: fprintf(stderr, "Unknown Error occurred ==> %d",result); } exit(256); } // // List the Results // printf(" Success\n"); // Add test of create_ticket function - wont be able to add though // because we already added it! int i; struct rd_ticketinfo *myticket=0; unsigned numrecs=0; result = RD_CreateTicket( &myticket, host, user, passwd, user_agent, &numrecs); if ((result< 200 || result > 299) && (result != 0)) { switch(result) { case 403: fprintf(stderr," ERROR: Invalid User Information During Create Ticket\n"); break; default: fprintf(stderr, "Unknown Error occurred ==> %d\n",result); } exit(256); } // We got a ticket created - use it and do the call again // // List the Results // for(i=0;i<numrecs;i++) { printf(" Ticket: %s\n",myticket[i].ticket); printf("Ticket Expire year value = %d\n",myticket->tkt_expiration_datetime.tm_year); printf("Ticket Expire month value = %d\n",myticket->tkt_expiration_datetime.tm_mon); printf("Ticket Expire day value = %d\n",myticket->tkt_expiration_datetime.tm_mday); printf("Ticket Expire wday value = %d\n",myticket->tkt_expiration_datetime.tm_wday); printf("Ticket Expire hour value = %d\n",myticket->tkt_expiration_datetime.tm_hour); printf("Ticket Expire min value = %d\n",myticket->tkt_expiration_datetime.tm_min); printf("Ticket Expire sec value = %d\n",myticket->tkt_expiration_datetime.tm_sec); printf("Ticket Expire isdst value = %d\n",myticket->tkt_expiration_datetime.tm_isdst); printf("\n"); } user=""; passwd=""; strcpy( ticket,myticket->ticket); fprintf(stderr, "Ticket was copied - = %s\n",ticket); // Delete the log before we try to use a ticket to add it. // // Call the function // result=RD_DeleteLog(host, user, passwd, ticket, logname, user_agent); if(result<0) { fprintf(stderr,"Something went wrong!\n"); exit(256); } if ((result< 200 || result > 299) && (result != 0)) { switch(result) { case 400: fprintf(stderr," ERROR: Invalid Parameter for LOG_NAME! \n"); break; case 500: fprintf(stderr, "ERROR: Unable to Delete Log! \n"); break; default: fprintf(stderr, "Unknown Error occurred ==> %d",result); } exit(256); } // // Call the function // result=RD_AddLog(host, user, passwd, ticket, logname, servicename, user_agent); if(result<0) { fprintf(stderr,"Something went wrong!\n"); exit(256); } if ((result< 200 || result > 299) && (result != 0)) { switch(result) { case 400: fprintf(stderr," ERROR: Invalid Parameter for LOG_NAME or SERVICE_NAME"); break; case 404: fprintf(stderr,"ERROR: No Such Service Exists! \n"); break; case 500: fprintf(stderr, "ERROR: Unable to Create Log! \n"); break; default: fprintf(stderr, "Unknown Error occurred ==> %d",result); } exit(256); } // // List the Results // printf(" Success\n"); // Remove the log for the final time // result=RD_DeleteLog(host, user, passwd, ticket, logname, user_agent); if(result<0) { fprintf(stderr,"Something went wrong!\n"); exit(256); } if ((result< 200 || result > 299) && (result != 0)) { switch(result) { case 400: fprintf(stderr," ERROR: Invalid Parameter for LOG_NAME! \n"); break; case 500: fprintf(stderr, "ERROR: Unable to Delete Log! \n"); break; default: fprintf(stderr, "Unknown Error occurred ==> %d",result); } exit(256); } printf("Log was deleted!\n"); exit(0); }