--------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F1W00011 Date: 01/25/98 From: ANTHONY TIBBS Time: 02:20pm \/To: ALL (Read 0 times) Subj: Finite State Machine - Extensions [1/3] ----- FSM.C begins ----- /********************************************************************/ /* Finite State Machine Processor */ /* Written and released to the public domain by Anthony Tibbs */ /* */ /* Similar to the processing used in BinkleyTerm, but slightly more */ /* generic. This was actually written as a 5 minute hack, but I */ /* figured that, since it extends on FSM.? in Snippets, why not */ /* tidy it up and post it? */ /* */ /* Testing with Turbo C++ 3.0 */ /* */ /* Revision History: */ /* 25-Jan-98 AAT Initial birth of FSM. */ /********************************************************************/ /* ** If you want debugging enabled, #define DEBUG. Of course, for most ** applications you will probably want to replace the calls to printf() ** with calls to some kind of "log" function... */ #ifdef DEBUG #include #endif #include "fsm.h" /* ** See example code (FSM_EXMPL.C) for more information. */ void FSM (FSM_StateP States, void *Struct, unsigned int Start_State) { unsigned int Cur_State=Start_State; ((FSM_Internals *)Struct)->Next = Cur_State; #ifdef DEBUG printf ("FSM: Starting at state %u (%s)\n", Cur_State, States[Cur_State-1].Name); #endif while (Cur_State) { #ifdef DEBUG printf ("FSM: State %u (%s)\n", Cur_State, States[Cur_State-1].Name); #endif Cur_State = (*States[Cur_State-1].Func) (Struct); } #ifdef DEBUG printf ("FSM: Exiting...\n"); #endif } ----- FSM.C ends ----- --- PointEd 2.0 * Origin: The Tibbs' Point - Ottawa, Ontario, Canada (1:163/215.38) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F1W00012 Date: 01/25/98 From: ANTHONY TIBBS Time: 02:20pm \/To: ALL (Read 0 times) Subj: Finite State Machine - Extensions [2/3] ----- FSM.H begins ----- #ifndef __FSM_H_INCLUDED__ #define __FSM_H_INCLUDED__ /********************************************************************/ /* Finite State Machine Processor */ /* Written and released to the public domain by Anthony Tibbs */ /* */ /* Similar to the processing used in BinkleyTerm, but slightly more */ /* generic. This was actually written as a 5 minute hack, but I */ /* figured that, since it extends on FSM.? in Snippets, why not */ /* tidy it up and post it? */ /* */ /* Testing with Turbo C++ 3.0 */ /* */ /* Revision History: */ /* 25-Jan-98 AAT Initial birth of FSM. */ /********************************************************************/ /* ** Used internally by FSM(). If the user is using one of their own ** structures, this MUST be first. (use of structure provides for ** easy expansion later on.) */ typedef struct { unsigned int Next; /* The next state to go to... */ } FSM_Internals; /* ** This structure is used for the "machine state" array... */ typedef struct { unsigned int ID; /* State ID # */ unsigned char Name [36]; /* State name */ unsigned short (*Func) (void *); /* The actual state function */ } FSM_State, *FSM_StateP; #endif /* __FSM_H_INCLUDED__ */ ----- FSM.H ends ----- --- PointEd 2.0 * Origin: The Tibbs' Point - Ottawa, Ontario, Canada (1:163/215.38) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F1W00013 Date: 01/25/98 From: ANTHONY TIBBS Time: 02:21pm \/To: ALL (Read 0 times) Subj: Finite State Machine - Extensions [3/3] ----- FSMTEST.C begins ----- /* ** Demonstration code for FSM.C/FSM.H ** Released to the public domain by Anthony Tibbs ** ** I couldn't think of any real-life example(s) in which an FSM would be ** useful that would be postable. (e.g. that wouldn't rely on other ** modules of a program) So, I'm using an example from a C tutorial: ** ** 2. Write a program that counts from one to fifteen, prints the ** values on a separate line for each, and includes a ** message of your choice when the count is 3, a ** different message when the count is 7, and yet a different ** message when the count is 14. ** ** Other than a `suspicious pointer conversion' warning, this works ** fine. (I imagine that is because of the void*/Counter_Struct* ** conversion.) ** */ #include "fsm.h" /* ** Structure to be passed about amongst the functions. */ typedef struct { FSM_Internals FSM; unsigned char Counter; /* Counter */ } Counter_Struct; /* ** State ID numbers */ #define INIT 1 #define UPDATE_CNTR 2 #define SHOW_NUMBER 3 #define SHOW_MESSAGE 4 #define CHK_FINISHED 5 /* ** State "functions" */ unsigned short Init (Counter_Struct *pCS) { pCS->Counter=0; return UPDATE_CNTR; } unsigned short Update_Counter (Counter_Struct *pCS) { pCS->Counter++; return SHOW_NUMBER; } unsigned short Show_Number (Counter_Struct *pCS) { printf ("%-2.2d ", pCS->Counter); return SHOW_MESSAGE; } unsigned short Show_Message (Counter_Struct *pCS) { switch (pCS->Counter) { case 3 : printf ("Programming\n"); return UPDATE_CNTR; case 7 : printf ("is\n"); return UPDATE_CNTR; case 14 : printf ("fun!\n"); return UPDATE_CNTR; default : printf ("\n"); return CHK_FINISHED; } } unsigned short Finished (Counter_Struct *pCS) { if (pCS->Counter == 15) return 0; /* Get out of this loop. */ return UPDATE_CNTR; } int main (void) { Counter_Struct c; FSM_State Machine_States[]= {/* ID# Name FunctionPtr */ {INIT, "Init", Init}, {UPDATE_CNTR, "Update Counter", Update_Counter}, {SHOW_NUMBER, "Show Number", Show_Number}, {SHOW_MESSAGE, "Show Message", Show_Message}, {CHK_FINISHED, "Are we done?", Finished}}; /* ** Do the machine states, passing "c" to each of them, starting at INIT. */ FSM (Machine_States, &c, INIT); return 0; } ----- FSMTEST.C ends ----- --- PointEd 2.0 * Origin: The Tibbs' Point - Ottawa, Ontario, Canada (1:163/215.38) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F1W00014 Date: 01/26/98 From: EMILIJAN MIRCESKI Time: 09:42am \/To: ALL (Read 0 times) Subj: Lord Hi all. Sorry about the message , its was posted in wrong conference. ... !!!|MAGIC BBS|++389 96 75419|22.00-06.00|!!! ___ Blue Wave/DOS v2.30 -+- OLMS 2.53 UNREG --- FMail/Win32 1.40g * Origin: Struga BBS +389 96 74074 * Macedonia * (2:383/0) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F1W00015 Date: 01/19/98 From: RUSLAN SAVIN Time: 07:57pm \/To: MODERATOR (Read 0 times) Subj: Rules!!!  -| ਢ ⥡ Moderator! ۲|- Subj.  -| Moderator! ۲|- --- WinNT-suxx must die! --- --- TM-Ed 1.14+ * Origin: த "ࠪ & ࠡ" (2:5079/5.37) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F1W00016 Date: 01/26/98 From: DARIN MCBRIDE Time: 07:31am \/To: SUNIR SHAH (Read 0 times) Subj: I'm back, again SS> Well, I'm back, at least temporarily. Who's the moderator of this ucket SS> anyway? Auke, is it still you? I have to know who I'm SS> offending, after all. We're in the middle of an election. I nominate Sunir. ;-) --- * Origin: Tanktalus' Tower BBS (1:250/102) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F1W00017 Date: 01/26/98 From: DAVE KELLY Time: 08:19pm \/To: ALL (Read 0 times) Subj: Help Needed In trying to compile some of the code posted on this echo, I keep comming across the functions 'findfirst()' and "findnext()'. I am not exactly sure what these functions do. Does findfirst just confirm that a file exist? Is the need to read a certain number of charecters neccessary? Does findnext confirm that the next file in a list exists? And why does it NOT need to read a certain number of bytes. If findfirst only confirms the existense of a file I can use the code offered below. ------snip------ #include #include #include #include #include #define MAX 1024 #define FALSE 0 #define TRUE !FALSE #define SUCCESS 5 DIR *dpath; struct direct *d_ent; char dirpath[32]; char FindString[32]; int i; char line[MAX][32]; char *tp[MAX]; int findnext(); int findnext( Sdir, Sstr, Nochar ) char *Sdir; char *Sstr; int *Nochar; { int cnt; i=0; strcpy( dirpath, Sdir ); strcpy( FindString, Sstr ); if( NULL == ( dpath = opendir( dirpath ))) { printf(" Cannot open path to directory < %s >\n", dirpath); exit(0); } while( NULL != ( d_ent = readdir( dpath ))) { if( d_ent->d_name[0] == '.' ) continue; strncpy( line[i], d_ent->d_name, strlen( d_ent->d_name )); tp[i] = line[i]; strcat( tp[i], '\0' ); i++; } closedir( dpath ); strcat( FindString, '\0' ); for( cnt = 0; cnt < i; cnt++ ) { if( 0 == ( strcmp ( FindString, tp[cnt] ))) return ( SUCCESS ); } } int main( argc, argv ) int argc; char **argv; { char SearchDir[32]; char SearchStr[32]; int Found; strcpy( SearchDir, *++argv ); strcpy( SearchStr, *++argv ); if ( SUCCESS == ( Found = findnext ( SearchDir, SearchStr ))) printf("Match Found\n"); return ( 0 ); } ------snip------ But how would I continue with findnext? And what would that code look like? I did notice that in one of the example in SNIPPETS, the function that used findfirst did nothing if compiled with the preproccessor flag __STDC__ set. Thanks for any help anyone can give. ... * ATP/OSK 1.40 * What grammar is to speech, logic is to reason. --- T.A.G. 2.7d Standard * Origin: Coyote's Den (1:106/3198) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F1W00018 Date: 01/25/98 From: ADAM MAJER Time: 07:07pm \/To: ALL (Read 0 times) Subj: Microsoft Address Could anyone post me an e-mail address to Microsoft's technical/programming department? Thanx in advance. I don't have Internet access except for e-mail thru a BBS. * SLMR 2.1a * Unable to locate Coffee -- Operator Halted! --- FMail 0.92 * Origin: The Programmer's Oasis on FIDONET! (1:348/203) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F1W00019 Date: 01/25/98 From: ADAM MAJER Time: 07:07pm \/To: ALL (Read 0 times) Subj: Virtual Key Codes Could anyone send me a complete list of Virtual Key codes for windows 3.1x and 95? What I have appears to be all screwed up. For example, is says a decimal is equivelent to 'n' key !??! Plus, it doesn't have any lowercase letters. I need it for the WM_CHAR function. Thanx in advance. ;-) Happy coding, Adam * SLMR 2.1a * --T-A+G-L-I+N-E--+M-E-A+S-U-R+I-N-G+--G-A+U-G-E-- --- FMail 0.92 * Origin: The Programmer's Oasis on FIDONET! (1:348/203) --------------- FIDO MESSAGE AREA==> TOPIC: 239 C LANGUAGE Ref: F1W00020 Date: 01/26/98 From: ASHER DENSMORE-LYNN Time: 09:19pm \/To: AUKE REITSMA (Read 0 times) Subj: FYI: POSTED IN THE C_PLUS 23 Jan 98 20:55, Auke Reitsma wrote to Carey Bloodworth: AR> I have already counted you as in favor of merging the echoes. Though AR> it really won't matter because you are outvoted according to the AR> current count. Reminding me: I'd vote against -- for I do not -like- C++, and wouldn't want to wade through it. (: Asher Densmore-Lynn ... Anarchy is against the law! --- Squish v1.11 * Origin: Phaenix Rampant, 'Uhm... I hit it again!' (1:130/115)